vue計算屬性想要傳入參數怎么辦


先講解決方案:

可以通過return 一個function來實現,在function中傳入想要傳給computed屬性的參數

<q-icon :name="getIcon(item.icon,index+1)" style="font-size:2em" @click="btnClicked(index+1)"/>
computed:{
        getIcon: function(){
            return function(iconName, tabIndex){
                return `${this.tabNum===tabIndex ? '' : 'o_'}${iconName}`;
            }
        },
        ...mapState({
            showSearchFriendDialog: 'showSearchFriendDialog',
            showChangeAvatarDialog: 'showChangeAvatarDialog',
            showCreateGroupDialog: 'showCreateGroupDialog',
            user: 'user'
        })
    },

再講一下我遇到的問題:

vue的v-bind屬性傳入一個computed函數,當該函數帶有參數的時候, 瀏覽器報錯,當不帶有參數的時候正常執行


下面這樣解決:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM