<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>directives用法</title>
</head>
<body>
<!-- 使用directive实现,不包含指定类名的标签,隐藏 -->
<div id="app">
<div v-aaa class="item-a">
item-a
</div>
<div v-aaa class="item-b">
item-b
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var vm = new Vue({
el: "#app",
data() {
return {
list: [
"item-a"
]
}
},
created() {
that = this;
},
directives: {
aaa(el) {
const index = that.list.findIndex((val) => {
return val === el.className
})
if (index === -1) {
el.style.display = 'none'
}
}
}
});
</script>
</body>
</html>
directives自定义指令
最新推荐文章于 2023-04-14 09:14:12 发布