vue 自定义指令


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of page</title>
</head>
<body>
<div id="exss">
<input v-focus>
</div>

</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.13/dist/vue.js"></script>
<script >
// 注册一个全局自定义指令 `v-focus`
// Vue.directive('focus', {
// // 当被绑定的元素插入到 DOM 中时……
// inserted: function (el) {
// // 聚焦元素
// el.focus()
// console.log(111)
// }
// })
new Vue({
el:"#exss",
directives: {
focus: {
// 指令的定义
inserted: function (el) {
el.focus()
}
}
}
})
</script>
</html>

原文地址:https://www.cnblogs.com/dianzan/p/8505104.html