jtwang7 / Vue-Note

Vue 学习笔记
0 stars 0 forks source link

Vue computed 传参 #5

Open jtwang7 opened 2 years ago

jtwang7 commented 2 years ago

Vue computed 传参

参考文章:vue computed传参

✅ 计算属性不能直接传参 ✅ 计算属性传参需要返回一个函数实现 (而不是单单返回一个值),通过调用返回的函数,传入具体参数来计算返回数据

export default {
    data () {
        return {}
    },
    computed: {
        test() {
            return function(index){
                return this.data[index].num       
            }           
        } 
    }
}
// computed() 里的写法
const isIconActive = computed(() => (id: number) => (id === currentIconId.value))