在 vue 應用程式中,我想在模板部分使用從引數定義的變數,通過 URL 傳遞。但是當我嘗試使用它時,在模板中使用時出現未定義的錯誤(盡管它在腳本部分中使用并按定義顯示)。
我認為回傳變數可以讓我在模板部分使用它,但我收到了重復鍵警告。
<template>
<div>
<router-link
:to="{ path: `/${m}`}" //this shows as
undefined
>Link</router-link
>
</div>
</template>
<script>
export default {
name: "template",
props: ["m"],
setup() {
const route = useRoute();
const m = ref(route.params.m);
console.log(m.value) //this works
return {
m //This shows as a duplicate key
};
},
};
</script>
uj5u.com熱心網友回復:
m在 setup() 中更改變數名稱。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/448429.html
標籤:Vue.js
