轉自:https://blog.csdn.net/weixin_44198965/article/details/99607987
前言
最近使用 vue 組件時,名稱使用了駝峰命名之后,組件寫在 html 代碼段中卻拋出錯誤。
HTML:
<div id="app"> <newButton></newButton> </div>
- 1
- 2
- 3
JavaScript:
Vue.component('newButton',{ data () { return {} }, template:'<button>示例按鈕</button>' }) new Vue({el:'#app'})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
錯誤:
vue給出的錯誤提示沒有找到組件,但事實是由駝峰命名所引起。
解決方法
在書寫組件 HTML 代碼段中,將大寫字母改為小寫,然后在前面加一個 " - " 號連接即可。
HTML:
<div id="app"> <new-button></new-button> </div>
- 1
- 2
- 3
JavaScript:
Vue.component('newButton',{ data () { return {} }, template:'<button>示例按鈕</button>' }) new Vue({el:'#app'})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8