【发布时间】:2019-07-04 04:33:46
【问题描述】:
我有以下组件:
<template>
<button class="button" @[click]="action">{{ text }}</button>
</template>
<script>
export default {
name: "Button",
props: {
action: {
type: Function,
required: false
},
text: {
type: String,
required: true
},
inputType: {
type: String,
required: false
}
},
computed: {
click() {
return this.action ? "click" : null;
}
}
};
</script>
但是,当我将函数作为带有参数的action 传递时,该函数已在渲染时触发。没有参数也可以正常工作。
<v-button inputType="button" :action="say('Hello')" text="Alert" />
<v-button inputType="button" :action="say" text="Alert" />
触发函数:
say(message) {
alert(message);
}
你可以看到here的行为。看着this,我希望它可以与传递参数一起使用。
所以我的问题是如何防止在渲染时触发?
【问题讨论】: