Function 如何使用vue.js在@click事件上添加两个方法?
这是我的代码,我基本上想将CHANGEBUTTONS添加到类似于@click的on-click事件中Function 如何使用vue.js在@click事件上添加两个方法?,function,methods,vue.js,onclick,Function,Methods,Vue.js,Onclick,这是我的代码,我基本上想将CHANGEBUTTONS添加到类似于@click的on-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</b
<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>
从收藏夹中删除
新Vue({
el:“#应用程序”,
数据:{
秀:没错,
盘状体:,
行动:“添加”,
行动2:“删除”,
编号:“
},
方法:{
enviarform:function(){
axios.post('/validarfavorite.php'{
paletteid:this.paletteid,
动作:这个动作
})
.然后(功能(响应){
控制台日志(响应);
})
.catch(函数(错误){
console.log(错误);
});
this.number=“您的plus”;
},
enviarform2:函数(){
axios.post('/validarfavorite.php'{
paletteid:this.paletteid,
行动2:这个
})
.然后(功能(响应){
控制台日志(响应);
})
.catch(函数(错误){
console.log(错误);
});
this.number=“减去您的加”;
},
changebuttons:function(){
this.show=!this.show;
}
}
});
我尝试了方法1、方法2和处理程序,但都不起作用。希望你知道 你不能简单地调用函数中的方法吗 您可以使用
分隔呼叫代码>(或以下代码):
我的按钮
但是,如果您的代码在多个地方使用,那么最佳实践(“最干净的方法”)是创建第三种方法并使用它:
我的按钮
演示:
newvue({
el:“#应用程序”,
数据:{
消息:“您好,Vue.js!”
},
方法:{
m1:function(){this.message+=“m1”;},
m2:function(){this.message+=“m2”;},
MONEAND二:函数(){
/*调用两个方法*/
这是m1();
这是m2();
}
}
})
{{message}}
调用两种方法使用
使用,
使用第三种方法调用两种方法
最简单的方法是:
<button v-on:click="method1(); method2();">Continue</button>
继续