引入組件時(shí)頁面上并沒有出現(xiàn)組件的影子,其他元素正常,初步確定是組件引入部分語法出了問題,打開開發(fā)者工具看到控制臺(tái)報(bào)出錯(cuò)誤代碼:
Failed to resolve component: MyButton If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.
翻譯文章來源:http://www.zghlxwxcb.cn/news/detail-702364.html
無法解析組件:我的按鈕如果這是本機(jī)自定義元素,請(qǐng)確保通過 compilerOptions.isCustomElement 將其從組件解析中排除。
搜到了博主們提供的一些方法比如:文章來源地址http://www.zghlxwxcb.cn/news/detail-702364.html
- 組件的script標(biāo)簽沒有添加 setup
- 引入的時(shí)候加了大括號(hào)之類的,這種情況很顯然不會(huì)報(bào)出這個(gè)錯(cuò)誤信息,而是下面這個(gè),而且也會(huì)影響頁面其他元素的加載
Uncaught SyntaxError: The requested module '/components/MyButton.vue?t=1676209371149' does not provide an export named 'MyButton'
最后經(jīng)過自己的排查,發(fā)現(xiàn)問題還是因?yàn)閷?dǎo)入組件時(shí),在components這一步出了問題導(dǎo)致的
<script>
import MyButton from '../components/MyButton.vue'
export default {
data() {
return {
msg: "我愛vue"
}
},
components: {
MyButton
}
}
</script>
<template>
<h1>{{ msg }}</h1>
<MyButton></MyButton>
<!-- <MyButton></MyButton> -->
</template>
到了這里,關(guān)于【Vue3】引入組件Failed to resolve component: MyButton If this is a native custom element的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!