当直接将setup写在script标签上
会报错vue-router.mjs:3451 TypeError: Failed to fetch dynamically imported module:
这是setup语法糖导致的错误,此时就老老实实按照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>
原始正常写法:文章来源:https://www.toymoban.com/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[]>([])
//获取所有标签
const getAllTags = async () => {
const res = await getTags();
tagList.value = res.data;
}
onMounted(() => {
getAllTags();
})
return {
tagList,
}
}
}
</script>
<style scoped>
</style>
改成原始写法后就不报错了!!!看来还是不能偷懒呀~文章来源地址https://www.toymoban.com/news/detail-656035.html
到了这里,关于setup语法糖报错 vue-router.mjs:3451 TypeError: Failed to fetch dynamically imported module:的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!