javascript - About vue2 triggering click event
为情所困
为情所困 2017-05-18 10:52:52
0
4
528

Now I have some li's that are bound to the click event @click="a()" and the id of each li is different. Now I want to trigger the @click event of the li with a certain id when I want to enter the page. May I ask how to write .click() using jQuery but it has no effect? ​​
For example
For example, the IDs of li are 1 2 3 4 5. I want to enter the page and trigger the @click event of li with ID 5. This can be solved using jQuery. Can also

为情所困
为情所困

reply all(4)
洪涛

@click="click ($index)"

Ty80

<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="UTF-8" />
<title>Document</title>

</head>
<body>

<p id="app">

<ul>

    <li @click="add1()"></li>
    <li @click="add2()"></li>
    <li @click="add3()"></li>
    <li @click="add4()"></li>
    <li @click="add5()"></li>
</ul>
</p>

<script src="https://cdn.bootcss.com/vue/2.3.3/vue.js"></script>
<script>
   var vm=new Vue({
        el:"#app",
        methods:{
            add1(){
                alert(1);
            }
        }
    });
    window.onload=function(){
         vm.add1();
    };
</script>

</body>
</html>

是这个意思?

小葫芦

The trigger of this dom is directly inside mounted

巴扎黑
<template>
    <ul>
        <li v-for="item in list" @click="handleClick(item.id)"></li>
    </ul
</template>

<script>
    export default {
        data() {
            return {
                list: [{id:1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}]
            }
        },
        
        mounted() {
            this.handleClick(5)
        },
        
        methods: {
            handleClick(id) {
                // 执行操作
            }
        }
    }
</script>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template