1 Star 0 Fork 0

朱建辉/vuetest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
component.html 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
朱建辉 提交于 2018-03-06 10:58 +08:00 . 修复
<script src='https://unpkg.com/vue@2.1.10/dist/vue.js'></script>
<div id="app">
<message content="hello boy"></message>
</div>
<script>
var Message=Vue.extend({
props:['content'],
template:'<h1>{{content}}</h1>'
});
Vue.component('message',Message);
var vm=new Vue({
el:'#app'
});
</script>
<!--标签和js分离-->
<div id="app2">
<p>123</p>
</div>
<script id="tpl" type="x-template">
<div class='tpl'>
   <p>This is a tpl from script tag</p>
</div>
</script>
<script type="text/javascript">
var vm = new Vue({
   el : '#app2',
   template : '#tpl'
});
</script>
<!--component的标准简单使用-->
<div id="app3">
<my-component title="这个标题" content="这个内容"></my-component>
</div>
<script>
var simplecon=Vue.component('my-component',{
props:['title','content'],
data:function(){
return {
desc:'123'
}
},
template:'<h1>{{title}}{{content}}{{desc}}</h1>'
});
var vm3=new Vue({
el:'#app3'
});
</script>
<!--父组件和子组件测试-->
<div id="app4">
父组件:<input type="text" v-model="msg" />
<my-bind :msg.sync="msg"></my-bind>
</div>
<script>
Vue.component('my-bind',{
props:['msg'],
template:'<div>子组件:<input type="text" v-model="msg" /></div>'
});
var vm4=new Vue({
el:"#app4",
data:{
msg:'123465'
}
});
</script>
<!--方法触发事件-->
<div id="app5">
<button @click="onClick">点击</button>
</div>
<script>
var vm5=new Vue({
el:'#app5',
events:{
add:function(msg){
console.log(msg);
}
},
methods:{
onClick:function(){
//this.$emit('add','there is add');//$emit测试
this.$dispatch('add','there is dispatch');
}
}
});
</script>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yushen123/vuetest.git
git@gitee.com:yushen123/vuetest.git
yushen123
vuetest
vuetest
master

搜索帮助