Vue父子、父子孙组件嵌套
2017-03-30 10:16
459 查看
单个组件的语法:
父子组件的写法:
父子嵌套实例:
父子孙组件嵌套:
父子组件另一种写法:
创建构造器 var MyComponent = Vue.extend({ template: '<div>A custom component!</div>' }); 注册组件 Vue.component('my-component', MyComponent);
父子组件的写法:
var child = Vue.extend({ template:"<h1>我是孩子</h1>" }); Vue.component("parent",{ template:"<h1>我是父亲<child1></child1></h1>", components:{ "child1":child } })
父子嵌套实例:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script src="vue.js" type="text/javascript"></script> </head> <body> <div id="box"> <parent></parent> </div> <script> window.onload=function(){ new Vue({ el:"#box" }); }; var child = Vue.extend({ template:"<h1>我是孩子</h1>" }); Vue.component("parent",{ template:"<h1>我是父亲<child1></child1></h1>", components:{ "child1":child } }) </script> </body> </html>
父子孙组件嵌套:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script src="vue.js" type="text/javascript"></script> </head> <body> <div id="box"> <parent></parent> </div> <script> window.onload=function(){ new Vue({ el:"#box" }); }; var child = Vue.extend({ template:"<h1>我是孙子</h1>" }); var son = Vue.extend({ template:"<h1>我是儿子<child1></child1></h1>", components:{ "child1":child } }); Vue.component("parent",{ template:"<h1>我是父亲<son1></son1></h1>", components:{ "son1":son } }) </script> </body> </html>
父子组件另一种写法:
var vm=new Vue({ el:"#box", data:{ a:"aaa" }, components:{ "aaa":{ template:"<h2>我是aaa</h2><bbb></bbb>", components:{ "bbb":{ template:"<h2>我是bbb</h2>", } } } } })
<div id="box"> <aaa></aaa> </div>
相关文章推荐
- vue父子组件嵌套的时候遇到 - Component template should contain exactly one root element. If you are using v-i
- vue父子组件的嵌套
- vue父子组件的嵌套的示例代码
- vue-父子组件嵌套的示例
- vue中非父子组件之间传递值
- vue父子组件通信
- vue非父子组件之间的通信
- Vue 非父子组件通信
- Vue表单类的父子组件数据传递示例
- Vue 实现组件 及 组件嵌套
- vue 组件递归,非父子间组件通信简单实例
- vue开发:vue父子组件与非父子组件之间的通信
- vue2.0父子组件通信的方法
- vue.js通过子组件通信和父子组件通信实现动态表单动态绑定事件(适合交互系统统一使用)
- [js高手之路]Vue2.0基于vue-cli+webpack父子组件通信教程
- vue2.0父子组件及非父子组件通信
- Vue 路由嵌套、数据请求、组件
- Vue2.0学习之详解Vue 组件及父子组件通信
- vue2.0父子组件及非父子组件之间的通信方法
- Vuejs——(10)组件——父子组件通信