我正在從 API (https://restcountries.com/) 獲取並顯示數(shù)據(jù),但我無(wú)法使用 router-link 標(biāo)記將每個(gè)表?xiàng)l目超連結(jié)到自己的頁(yè)面。什麼也沒(méi)發(fā)生,沒(méi)有錯(cuò)誤,沒(méi)有連結(jié)文字。
<template> <div> <b-table responsive head-variant="dark" striped hover :items="countries" :fields="headings"> <template #cell(name)="data"> <router-link :to="{name: 'country', params: {country: country.name.official}}"> {{ data.value }} </router-link> </template> </b-table> </div> </template> <script> import axios from '@/config' export default { name: 'AllCountries', components: {}, data() { return { headings: [ { key: 'name.common', sortable: true }, { key: 'capital', sortable: true }, ], countries: [] } }, mounted() { axios.get('/all') .then(response => { console.log(response.data) this.countries = response.data }) .catch(error => console.log(error)) } } </script>
如果我從鍵“名稱”中刪除 .common,router-link 可以工作,但它將顯示國(guó)家/地區(qū)名稱的所有變體,而不僅僅是我想要的一個(gè)“通用”名稱。此外,如果刪除 .common,路由器連結(jié)將無(wú)法運(yùn)作,如下所示:
“類型錯(cuò)誤:無(wú)法讀取未定義的屬性(讀取“名稱”)” 「屬性或方法「國(guó)家」未在實(shí)例上定義,而是在渲染期間引用?!?/p>
雖然我在其他地方?jīng)]有使用這個(gè)確切的路由器連結(jié)得到這些錯(cuò)誤,並且這些文件中沒(méi)有定義「名稱」),但我獲得路由器連結(jié)連結(jié)的唯一方法是使用這些參數(shù): { id: data.item._id }
(儘管它沒(méi)有連結(jié)到任何內(nèi)容(它嘗試連結(jié)到'/undefined?fullText=true'))
路由器連結(jié)的參數(shù)應(yīng)該是 params: {country: data.item.name.official }}