日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

组件命名方式||局部组件注册:局部组件只能在注册他的父组件中使用

發(fā)布時間:2025/4/16 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 组件命名方式||局部组件注册:局部组件只能在注册他的父组件中使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

組件命名方式

組件注冊注意事項
? ? ? ? ? ? ? ? 如果使用駝峰式命名組件,那么在使用組件的時候,只能在字符串模板中用駝峰的方式使用組件,但是
? ? ? ? ? ? ? ? 在普通的標(biāo)簽?zāi)0逯?#xff0c;必須使用短橫線的方式使用組件




<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Document</title> </head> <body><div id="app"><button-counter></button-counter><hr><!--<HelloWorld></HelloWorld> 這種寫法是錯誤的 --><hello-world></hello-world></div><script type="text/javascript" src="js/vue.js"></script><script type="text/javascript">Vue.component('HelloWorld', {data: function(){return {msg: 'HelloWorld'}},template: '<div>{{msg}}</div>'});Vue.component('button-counter', {data: function(){return {count: 0}},template: `<div><button @click="handle">點擊了{(lán){count}}次</button><button>測試123</button><HelloWorld></HelloWorld></div>`,methods: {handle: function(){this.count += 1;}}})var vm = new Vue({el: '#app',data: {}});</script> </body> </html>



局部組件注冊

局部組件注冊 局部組件只能在注冊他的父組件中使用

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Document</title> </head> <body><div id="app"><hello-world></hello-world><hello-tom></hello-tom><hello-jerry></hello-jerry><test-com></test-com></div><script type="text/javascript" src="js/vue.js"></script><script type="text/javascript">Vue.component('test-com',{// template: '<div>Test<hello-world></hello-world></div>' 這個是錯誤的 <hello-world></hello-world> 是局部組件template: '<div>Test</div>'});var HelloWorld = {data: function(){return {msg: 'HelloWorld'}},template: '<div>{{msg}}</div>'};var HelloTom = {data: function(){return {msg: 'HelloTom'}},template: '<div>{{msg}}</div>'};var HelloJerry = {data: function(){return {msg: 'HelloJerry'}},template: '<div>{{msg}}</div>'};var vm = new Vue({el: '#app',data: {},components: {'hello-world': HelloWorld,'hello-tom': HelloTom,'hello-jerry': HelloJerry}});</script> </body> </html>

總結(jié)

以上是生活随笔為你收集整理的组件命名方式||局部组件注册:局部组件只能在注册他的父组件中使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。