This time I will bring you the custom directive directive of Vue.js. What are the precautions for using the custom directive directive of Vue.js? The following is a practical case, let’s take a look.
Take custom v-css instructions as an example:
Local instructions
Global instructions
Customize global instructions in the main.js file
Vue.directive('css', { inserted (el, binding) { let styleObj = binding.value let arr = [] for (let key in styleObj) { arr.push(key + ':' + styleObj[key]) } arr = arr.join(';') el.style.cssText = arr } })
Use custom instructions
我是p标签
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
Computed properties and data monitoring of Vue.js
Vue.js events Binding - built-in event binding, custom event binding
Vue.js list rendering v-for array object subcomponent
The above is the detailed content of Vue.js custom directive directive. For more information, please follow other related articles on the PHP Chinese website!