繁体   English   中英

在页面函数内调用插件函数不起作用

[英]Call a plugin function inside a page function doesn't works

我在 plugins/ 中创建了一个名为 helper.js 的插件,但是当我在另一个函数中调用它时,我的插件函数不起作用,这是我的代码: helper.js

    import Vue from 'vue'
import $ from 'jquery'
import toastr from 'toastr'

Vue.mixin({
  methods: {
    test () {
      alert('test is called correctly')
    }
  }
})

页面/index.vue代码:

mounted () {
/** Create the cartesian option for products variants **/
const classname = document.getElementsByClassName('main-input')
// call the cartesian function from plugins/helper.js and listen to each .maini-input class on change

const myFunction = function () {
  this.test()
}
for (let i = 0; i < classname.length; i++) {
  classname[i].addEventListener('keyup', myFunction)
 }
}

您是否将您的插件注册到nuxt.config.js文件中?

export default {
  ...
  plugins: [
    '~/plugins/helpers.js'
  ]
}

https://nuxtjs.org/guide/plugins

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM