1. 程式人生 > >vue 自定義指令

vue 自定義指令

pos ons scrip 自定義指令 new http 一個 ctype function


<!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/[email protected]/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>

vue 自定義指令