简体   繁体   English

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

[英]How to get methods declared in vue inside swiper events

How to get methods declared in vue inside swiper events?如何在 swiper 事件中获取在 vue 中声明的方法?

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

Now i use现在我用

const vue = this

but i think, it's not good way但我认为,这不是好方法

data() method is not designed to create complex objects with methods. data()方法不是为了使用方法创建复杂的对象而设计的。 You can just create an empty variable in data() method, then fill it with your object in created hook or mounted hook.您可以在data()方法中创建一个空变量,然后在created钩子或mounted钩子中用您的对象填充它。 You'll be able to access the component via this variable if use arrow-function for init method inside your object.如果在对象内使用箭头函数作为init方法,您将能够通过this变量访问组件。

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

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