日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

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

組件命名方式

組件注冊注意事項
? ? ? ? ? ? ? ? 如果使用駝峰式命名組件,那么在使用組件的時候,只能在字符串模板中用駝峰的方式使用組件,但是
? ? ? ? ? ? ? ? 在普通的標簽模板中,必須使用短橫線的方式使用組件




<!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">點擊了{{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>

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。