【发布时间】:2017-12-31 05:57:09
【问题描述】:
我正在尝试允许用户从应用程序重置或关闭给定服务器。我现在正在处理界面,并希望向用户提供有关正在发生的事情的消息。我显示在我的数据对象中定义的消息以指示所采取的操作。然后我使用 setTimeout 切换重置....消息和重置消息。看下面的方法。
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是一个字符串,你如何以及何时显示它? -
难道是在timeout函数中使用
this关键字,所以指的是timeout函数而不是systemReset? -
我在我的段落中输出它
-
但只有一次..?
-
@PatrickMcDermott 也许,会发生这种情况吗?
标签: javascript methods vue.js