如何在swiper事件中获取在vue中声明的方法

时间:2018-06-14 14:56:50

标签: javascript vue.js swiper vue-ssr

如何在swiper事件中获取在vue中声明的方法?

export default {
    data() {
       let obj = {
           swiperOption: {
               ...
               on: {
                init: function () {
                    //need call someMethod in this place
                }
            }
        };
        return obj;
    }
    methods: {
        someMethod (){}
    }
}

现在我用

const vue = this

但我认为,这不是好方法

1 个答案:

答案 0 :(得分:0)

data() 方法不是用来创建带有方法的复杂对象的。您可以在 data() 方法中创建一个空变量,然后在 created 钩子或 mounted 钩子中用您的对象填充它。如果您的对象内的 this 方法使用箭头函数,您将能够通过 init 变量访问组件。

相关问题