當(dāng)直接將setup寫在script標(biāo)簽上
會報錯vue-router.mjs:3451 TypeError: Failed to fetch dynamically imported module:
這是setup語法糖導(dǎo)致的錯誤,此時就老老實實按照vue3原本的寫法export default{xxxxxx}即可解決
vue3中setup語法糖寫法:
<template>
<button @click="test">測試</button>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const a = ref(0);
const test = () => {
console.log(a)
}
</script>
<style scoped></style>
原始正常寫法:文章來源:http://www.zghlxwxcb.cn/news/detail-656035.html
<template>
<div v-for="tag in tagList" :key="tag.id">
<span>{{ tag.tagName }}</span>
</div>
</template>
<script lang="ts">
import { getTags } from '@/api/tag';
import { tag } from '@/types/api/tag';
import { onMounted, ref } from 'vue';
export default {
name: "Labels",
setup() {
let tagList = ref<tag[]>([])
//獲取所有標(biāo)簽
const getAllTags = async () => {
const res = await getTags();
tagList.value = res.data;
}
onMounted(() => {
getAllTags();
})
return {
tagList,
}
}
}
</script>
<style scoped>
</style>
改成原始寫法后就不報錯了?。。】磥磉€是不能偷懶呀~文章來源地址http://www.zghlxwxcb.cn/news/detail-656035.html
到了這里,關(guān)于setup語法糖報錯 vue-router.mjs:3451 TypeError: Failed to fetch dynamically imported module:的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!