vue-组件
Posted lanlanDong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue-组件相关的知识,希望对你有一定的参考价值。
1
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="bower_components/vue/dist/vue.js"></script> <style> </style> </head> <body> <div id="box"> <!-- <aaa></aaa> --> </div> <script> var Aaa=Vue.extend({ template:‘<h3>我是标题3</h3>‘ }); var a=new Aaa(); console.log(a); var vm=new Vue({ el:‘#box‘, data:{ bSign:true } }); </script> </body> </html>
2
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="bower_components/vue/dist/vue.js"></script> <style> </style> </head> <body> <div id="box"> <aaa></aaa> </div> <script> var Aaa=Vue.extend({ template:‘<h3>我是标题3</h3>‘ }); Vue.component(‘aaa‘,Aaa); var vm=new Vue({ el:‘#box‘, data:{ bSign:true } }); </script> </body> </html>
3
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="bower_components/vue/dist/vue.js"></script> <style> </style> </head> <body> <div id="box"> <aaa></aaa> </div> <script> var Aaa=Vue.extend({ template:‘<h3>{{msg}}</h3>‘, data(){ return { msg:‘ddddd‘ } } }); var vm=new Vue({ el:‘#box‘, data:{ bSign:true }, components:{ //局部组件 aaa:Aaa } }); </script> </body> </html>
4
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="bower_components/vue/dist/vue.js"></script> <style> </style> </head> <body> <div id="box"> <my-aaa></my-aaa> </div> <script> var Aaa=Vue.extend({ template:‘<h3>{{msg}}</h3>‘, data(){ return { msg:‘ddddd‘ } } }); var vm=new Vue({ el:‘#box‘, data:{ bSign:true }, components:{ //局部组件 ‘my-aaa‘:Aaa } }); </script> </body> </html>
以上是关于vue-组件的主要内容,如果未能解决你的问题,请参考以下文章