Al escribir la configuración directamente en la etiqueta del script
Informará un errorvue-router.mjs:3451 TypeError: Failed to fetch dynamically imported module:
Este es un error causado por el azúcar de sintaxis de configuración. En este momento, se puede resolver siguiendo el método de escritura original de vue3, export default{xxxxxx}
Cómo escribir azúcar de sintaxis de configuración en vue3:
<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>
Escritura normal original:
<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>
Después de cambiar al método de escritura original, ¡el error ya no aparecerá! ! ! Parece que no puedo ser flojo~