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
PHP中文网2017-05-18 10:54:52
<!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>
是这个意思?
巴扎黑2017-05-18 10:54:52
<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>