Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using Nuxt.js and I have this problem, with reading the running property of my client object.

(我正在使用Nuxt.js,但在读取客户端对象的running属性时遇到了这个问题。)

HTML:

(HTML:)

<b-button
  v-show="!(projectSelecter(project.ID)).isStarted"  //this work just fine
  variant="success"
  class="control_buttons"
  @click="start(project.ID)"
>Start</b-button>

JS:

(JS:)

start: function(id) {
  const client=this.projectSelecter(id);
  console.log("ID: ", id);
  console.log("Client: ", client);
  console.log("Client running property: ", client.running);
  //if (client.running) return;

  if (client.timeBegan === null) {
    this.reset();
    client.timeBegan = new Date();
  }

  if (client.timeStopped !== null) {
    client.stoppedDuration += new Date() - client.timeStopped;
  }

  client.isStarted=!client.isStarted;
  client.started = setInterval(this.clockRunning, 10);
  client.running = true;
},

This is the reset function, which is called in the start function above.

(这是复位功能,在上面的启动功能中调用。)

reset: function(id) {
  var client=this.projectSelecter(id);
  client.running = false;
  clearInterval(client.started);
  client.stoppedDuration = 0;
  client.timeBegan = null;
  client.timeStopped = null;
  client.time = "00:00";
  client.isStarted=false;
}

Console logs:

(控制台日志:)

在此处输入图片说明

Error message:

(错误信息:)

在此处输入图片说明

Full:

(充分:)

在此处输入图片说明

  ask by Alex Denor translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
280 views
Welcome To Ask or Share your Answers For Others

1 Answer

In your reset method, You need to pass id as parameter in the start method.

(在您的reset方法中,您需要在start方法中传递id作为参数。)

So your start method should look like

(所以你的启动方法应该像)

start: function(id) {
  const client=this.projectSelecter(id);
  console.log("ID: ", id);
  console.log("Client: ", client);
  console.log("Client running property: ", client.running);
  //if (client.running) return;

  if (client.timeBegan === null) {
    this.reset(id); //passing `id` to reset method
    client.timeBegan = new Date();
  }

  if (client.timeStopped !== null) {
    client.stoppedDuration += new Date() - client.timeStopped;
  }

  client.isStarted=!client.isStarted;
  client.started = setInterval(this.clockRunning, 10);
  client.running = true;
},

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...