这是我的代码,我基本上想要将CHANGEBUTTONS添加到看起来像@click的点击事件中。
<button @click="enviarform2" value="Delete from favorites" style="font-weight: 700;color:#428bca;margin-left:30px;height:30px;border-radius:4px" name="delete" v-else>Delete from favorites</button>
<script>
new Vue({
el:'#app',
data:{
show: true,
paletteid : <?=$palette_id;?>,
action: "add",
action2: "delete",
number: ""
},
methods: {
enviarform: function() {
axios.post('/validarfavorite.php', {
paletteid: this.paletteid,
action: this.action
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
this.number = "Yours plus ";
},
enviarform2: function() {
axios.post('/validarfavorite.php', {
paletteid: this.paletteid,
action2: this.action2
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
this.number = "Minus yours plus ";
},
changebuttons: function() {
this.show = !this.show;
}
}
});
</script>
我尝试过方法1和方法2以及处理程序,但它没有用。希望你知道!
答案 0 :(得分:3)
以最简单的形式,您可以使用模板:
<button @click="handleButtonClick">my button</button>
在您的JavaScript代码中执行:
new Vue({
el:'#app',
data:{
show: true,
// ...
},
methods: {
m1: function() { /* ... */ },
m2: function() { /* ... */ },
handleButtonClick: function() {
/* call two methods. */
this.m1();
this.m2();
}
}
})
您还可以使用JavaScript's comma operator:
<script src="https://unpkg.com/vue"></script>
<div id="app">
<p>{{ message }}</p>
<button @click="m1(), m2()">two methods</button>
</div>
new Vue({
el: '#app',
data: {
message: 'Hello Vue.js!'
},
methods: {
m1() { this.message += "m1"; },
m2() { this.message += "m2"; }
}
})
答案 1 :(得分:2)
最简单的方法是:
<button v-on:click="method1(); method2();">Continue</button>
答案 2 :(得分:0)
你不能简单地调用函数内部的方法吗?