首页 > 代码库 > vue19 组建 Vue.extend component
vue19 组建 Vue.extend component
<!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"> </div> <script> var Aaa=Vue.extend({//继承出来一个Vue类Aaa template:‘<h3>我是标题3</h3>‘ }); var a=new Aaa();//a跟vm一样 console.log(a); var vm=new Vue({ el:‘#box‘, data:{ bSign:true } }); </script> </body> </html>
<!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);//aaa是组建实例,全局组件 var vm=new Vue({ el:‘#box‘, data:{ bSign:true } }); </script> </body> </html>
<!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({ data(){ return { msg:‘我是标题^^‘ }; }, template:‘<h3>{{msg}}</h3>‘ }); Vue.component(‘aaa‘,Aaa); var vm=new Vue({ el:‘#box‘, data:{ bSign:true } }); </script> </body> </html>
<!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({ data(){ return { msg:‘我是标题^^‘ }; }, methods:{ change(){ this.msg=‘changed‘ } }, template:‘<h3 @click="change">{{msg}}</h3>‘ }); Vue.component(‘aaa‘,Aaa); var vm=new Vue({ el:‘#box‘, data:{ bSign:true } }); </script> </body> </html>
<!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(){// es6语法,函数不写:,组件里面放数据: data必须是函数的形式,函数必须返回一个对象(json) return { msg:‘ddddd‘ } } }); var vm=new Vue({ el:‘#box‘, data:{ bSign:true }, components:{ //局部组件,放到某个组件内部,Vue.component(‘aaa‘,Aaa); aaa:Aaa } }); </script> </body> </html>
<!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>
<!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> Vue.component(‘my-aaa‘,{//全局,公共的提出去 template:‘<strong>好</strong>‘ }); var vm=new Vue({ el:‘#box‘ }); </script> </body> </html>
<!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 vm=new Vue({ el:‘#box‘, components:{ //局部 ‘my-aaa‘:{ data(){ return { msg:‘welcome vue‘ } }, methods:{ change(){ this.msg=‘changed‘; } }, template:‘<h2 @click="change">标题2->{{msg}}</h2>‘ } } }); </script> </body> </html>
vue19 组建 Vue.extend component
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。