一、在main.js中自定义指令
Vue.directive('focus', {
// 当被绑定的元素插入到 DOM 中时……
inserted: function (el) {
// 聚焦元素
el.focus()
}
})
二、在页面中使用自定义指令:
<template>
<div >
<h3>自定义指令测试</h3>
<input v-focus/>
</div>
</template>
<script>
//import Vue from 'vue'
export default{
components: {
},
data() {
return {
}
},
methods:{
},
created(){
},
computed: {
},
watch: {
}
}
</script>
<style >
</style>