<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<input type="text" v-model="searchName" v-focus v-color="'red'" v-font-size="24">
</div>
<script src="../js/vue.js"></script>
<script>
const vm = new Vue({
el:'#app',
data:{
searchName:'春风',
},
directives :{
color:{
bind(el,binding){
el.style.color = binding.value;
}
},
'font-size': function (el,binding) {
el.style.fontSize = binding.value + 'px';
}
}
})
Vue.directive('focus',{
bind:function (el) {
},
inserted:function (el) {
el.focus()
},
updated:function (el) {
}
})
</script>
</body>
</html>
vue-其他自定义指令.html
最新推荐文章于 2024-07-30 10:56:44 发布