我只需要一些幫助來確定為什么我的計算屬性出現錯誤。錯誤是:
Error in render: "TypeError: Cannot read property 'length' of undefined"
我假設當我參考 this.node 時,我正在遍歷 activeConnect.nodes,它也不知道我指的是哪一個?如何修復我的計算機以正確執行此操作?
<v-col
v-for="(node, index) in activeConnect.nodes"
:key="index"
>
<v-card
flex
@click="edit(node)"
>
<v-card-text
:class="nameClass"
text-no-wrap
v-text="node.content"
/>
</v-card>
</v-col>
計算:
computed: {
nameClass () {
if (this.node.content.length > 4) {
return 'name-small'
}
return 'name'
}
}
SCSS:
.name-small {
font-size: 12px !important;
}
.name {
font-size: 20px !important;
}
uj5u.com熱心網友回復:
沒有this.node,node里面是本地名稱v-for。有幾個選項可以解決這個問題。
nameClass可以是node作為引數接收的方法。
依賴于nodevalue ( v-card)的模板的一部分可以移動到一個單獨的組件,該組件node作為 prop接收并可以進行nameClass計算。
像 in 這樣的簡單計算nameClass可以移動到模板中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/370445.html
標籤:javascript Vue.js
