|| Решено || Добавьте директивы Vue в Nuxt (только для КЛИЕНТА) - PullRequest
0 голосов
/ 05 марта 2020

Как добавить директивы в nuxt:

Примечание: это только для клиентской стороны

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-компонентный. vue

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