代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.3/vue.js"></script>
</head>
<body>
<div id="app">
<component v-bind:is="currentView">
</component>
<my-component>
<!-- 通过name可以绑定到对应的dom元素上-->
<p slot="first">hellow</p>
<p slot="second">{{name}}</p>
</my-component>
<test-component message="hello"></test-component>
<!--动态绑定父类的属性 通过props-->
<test-component v-bind:message="name"></test-component>
<table>
<tr is="test-component"></tr>
</table>
</div>
<script>
//全局注册
Vue.component('my-component', {
"template":"<h1><slot name='first'></slot>this is h1<slot name='second'></slot><a href=''>dd</a></h1>",
// 选项
});
let vm = new Vue({
el:"#app",
data:{
"name":"zhang",
currentView:"test-component"
},
//局部注册
components:{
"test-component":{
//绑定事件
template:"<button v-on:click='test'>{{num}}{{message}}</button>",
// 组件的data必须是函数 返回值必须是object
data:function(){
return {num:1};
},
props: ['message'],
methods:{
test:function(){
return this.num++;
}
}
}
},
methods:{
//通过自定义事件将数据回传给子类。
test:function () {
return this.num++;
}
}
});
</script>
<!--
组件通信
-->
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。