|| SOLVED || Add Vue directives in Nuxt (CLIENT side only)

与世无争的帅哥 提交于 2020-05-28 09:43:26

问题


How to add directives in nuxt:

Note: this is only for client-side

1- /plugins/directives.js:

import Vue from 'vue'

Vue.directive('getelement', {
  bind(el, { value: { index, items } }) {
    el.addEventListener('click', (event) => {
      event.stopPropagation()
      console.log(el, index, items)
      // do whatever 
    })
  }
})

2- /nuxt.config.js

plugins: [
   ...
   // DIRECTIVES : client ONLY
  { src: '~/plugins/directives.js', mode: 'client' }
]

3- component.vue

    <img
      v-for="(item, index) in items"
      v-getelement="{ items, index}"
      :key="index"
      :src="item.src"
    />

来源:https://stackoverflow.com/questions/60544698/solved-add-vue-directives-in-nuxt-client-side-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!