Javascript 调用页面函数内的插件函数';t工作
我在plugins/helper.js中创建了一个插件,但是当我在另一个函数中调用它时,我的插件函数不起作用 这是我的代码:helper.jsJavascript 调用页面函数内的插件函数';t工作,javascript,vue.js,nuxt.js,Javascript,Vue.js,Nuxt.js,我在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') } } }) 页面/索引.v
import Vue from 'vue'
import $ from 'jquery'
import toastr from 'toastr'
Vue.mixin({
methods: {
test () {
alert('test is called correctly')
}
}
})
页面/索引.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)
}
}
mounted(){
/**为产品变量创建笛卡尔选项**/
const classname=document.getElementsByClassName('main-input')
//从plugins/helper.js调用笛卡尔函数,并在更改时侦听每个.maini输入类
常量myFunction=函数(){
这个测试()
}
for(设i=0;i
您是否已将插件注册到numxt.config.js
文件中
export default {
...
plugins: [
'~/plugins/helpers.js'
]
}
是否将mixin包含在
index.vue
mixin
属性中?不,我该怎么做?那个api页面有一个完整的例子同样的问题:(.我的插件函数工作得很好,但当我在MyFunction中调用我的插件函数时它不工作。然后请更新你的问题,以显示你是如何在组件中包含mixin的