我试图让用户从应用程序重置或关闭给定的服务器。我现在在界面上工作,并且想给用户关于正在发生的消息。我在我的数据对象中显示一条消息以指示所采取的操作。我使用setTimeout来切换重置消息和重置消息。请参阅以下方法。setTimeout()not working从vueJS方法调用
systemReset: function(){
this.message = this.server + ': Resetting';
setTimeout(function(){
this.message = this.server + ': Reset';
}, 2000);
}
在我的浏览器我可以触发这个消息,我的“重置”显示的消息,但下面的“复位”消息是从来没有输出。我有任何格式错误?
把这个方法放在上下文中是我的整个组件。
<template>
<div>
<p>{{message}}</p>
<button @click="systemReset">Reset Server</button>
<button @click="systemPowerDown">Poweroff Server</button>
</div>
</template>
<script type="text/javascript">
export default{
data: function(){
return{
message: ''
}
},
methods: {
systemPowerDown: function(){
this.message = this.server + ': Server Down';
},
systemReset: function(){
this.message = this.server + ': Resetting';
setTimeout(function(){
this.message = this.server + ': Reset';
}, 2000);
}
},
props: ['server']
}
</script>
Am I missing something obvious? Or is there some vue limitation I am unaware of?
'this.message'是一个字符串,如何以及何时你显示它? – Teemu
是否可以在超时函数中使用'this'关键字,所以它指的是超时函数而不是systemReset? –
我输出它在我的段落 – DMrFrost