欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 手游 > vue2面试题——指令

vue2面试题——指令

2025/5/6 18:40:34 来源:https://blog.csdn.net/m0_66706006/article/details/139997984  浏览:    关键词:vue2面试题——指令

1. 如何自定义指令

全局指令:在main.js里面写

/* 全局自定义指令 */
// main.js文件
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'Vue.config.productionTip = falseVue.directive('demo',{inserted: function(a,b,c){console.log(a,b,c)}
})new Vue ({router,store,render: h => h(App)
}).$mount('#app')// 任意一个vue文件去使用
<template><div><div v-demo='123'></div></div>
</template>

局部指令:在某一个组件内写

// 任意一个vue文件
<template><div><div v-demo='123'>22222</div></div>
</template><script>
export default {directives: {demo:{bind: function(el){console.log(1)}}}
}
</script>

2. vue单项绑定

vue的双向绑定是v-model

vue中的单项绑定是v-bind

3. v-if和v-for的优先级

在vue2中,v-for的优先级是大于v-if的。

在vue3中,v-if的优先级是大于v-for的。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词