<div :class='["tab-item", menu.isShow === 1 ? "tab-item-on" : ""]' v-for='(menu, idx) in menuList' :key='idx'>
<div class="tab-tl" @click='showTab(idx)'>{{menu.name}}</div>
<div :class='["tab-icon", menu.isShow === 1 ? "" : "tab-icon-off"]' @click='delTab(idx)'>X</div>
</div>
setup() {
let menuDefault: MenuSave[] = [
{
name: '首页',
isShow: 0,
urlName: 'Home'
}, {
name: '会员1',
isShow: 0,
urlName: 'Leaguer'
}, {
name: '会员2',
isShow: 0,
urlName: 'Leaguer'
}, {
name: '会员',
isShow: 1,
urlName: 'Leaguer'
}
]
let menuList = reactive(menuDefault)
function showTab (idx) {
menuList = menuList.map((i, k) => {
if (k === idx) {
i.isShow = 1
}
return i
})
console.log('show', menuList)
}
function delTab (idx) {
menuList = menuList.filter((i, k) => k !== idx)
console.log('del', menuList)
}
return {
menuList,
showTab,
delTab
}
问题是:
1、 用reactive创建了一个响应式数组,后台console打印出来可见数组也发生变化,但是页面上监听不到,显示的依然是原来的内容
2、 用ref创建响应式数组,则无法使用数组的方法如map、filter等
请问各位大神有何高见???
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…