文章詳情頁
vue計算屬性怎么樣與for結合使用
瀏覽:140日期:2023-06-13 13:42:47
問題描述
<div v-for='item in items'> {{reversedMessage}}</div>export default{ computed: { reversedMessage: function () { return item.hometeam?"ok":"no" }}
在computed中沒有item這個屬性,要如何在computed計算items每一項呢?總不能computed也來一個循環(huán)吧。
問題解答
回答1:你混用了這個方法啊,你這定義computed的reversedMessage默認為get時候計算,此時的回調函數(shù)是綁定了this的,這個時候的this是data,你可以嘗試console.log(this)看一下。
我的建議是模板中直接寫
{{item.hometeam?'ok':'no'}}
標簽:
vue
相關文章:
排行榜

熱門標簽