vuejs-challenges
vuejs-challenges copied to clipboard
24 - 激活的样式-指令
// 你的答案
`
/**
- Implement the custom directive
- Make sure the list item text color changes to red when the
toggleTab
is toggled
*/ const VActiveStyle = { mounted(el:HTMLElement,binding:DirectiveBinding){ const [style,isTrue]=binding.value watchEffect(()=>{ for(let key in style){ if(isTrue()){ el.style[key]=style[key] }else{ el.style[key]='' } } }) } }
const list = [1, 2, 3, 4, 5, 6, 7, 8] const activeTab = ref(0) function toggleTab(index: number) { activeTab.value = index }
- {{ item }}