Get the calling element with vue.js

后端 未结 3 855
隐瞒了意图╮
隐瞒了意图╮ 2021-02-13 12:54

I want to get the calling html element in vue.js to modify it via jQuery. For now I give every element the class name + the index and call it via jQuery afterwards, but this loo

3条回答
  •  孤独总比滥情好
    2021-02-13 13:08

    Youre doing it the wrong way.

    new Vue({
        el: "#app",
        data: {  
            testFunction : function(element) {
                $(element).doSomethingWithIt(); //do something with the calling element
            }
        }
    });
    

    data is the state or storage of data for your app.

    you need to create methods object for your methods

    new Vue({
        el: "#app",
        data: {  
    
        },
        methods: {
    
        testFunction : function(element) {
                $(element).doSomethingWithIt(); //do something with the calling element
            }
        }
    
    });
    

提交回复
热议问题