如何为特定的数据值执行一次的方法

问题描述 投票:0回答:1

我有一个web应用程序,通过步骤显示不同的内容去。在我的数据财产,每递增下一步按钮被击中时:我有“0数据”的值。用户能够回去的步骤,如果需要进行更改。

我正在试图做的是有一个方法火一旦当它击中某一步。我可以使用V系列:变化来检查这个特定的数据值,如果是的话,我会地方处理?这个方法应该只能发射它击中的具体步骤,以避免出现问题,当用户可以追溯到第一次。

data: {

 addedKeywords: false,
 newAds:[
  []
  ]
 },
 methods: {
 baseAds(){
  if(this.step3Base == false){
    this.newAds[0].push({
      id: 0,
      headline1: 'Headline 1',
      headline2: 'Headline 2',
      headline3: 'headline3',
      desc1: 'This is your description 1',
      desc2: 'This is your description 2',
      finalurl: 'www.finalURL.com',
      path1: '',
      path2: '',
      boolean: true
    })
    for(var x = 1; x < this.options.length; x++){
      this.newAds.push([]);
    }
  }
  this.step3Base = true;
 },
 restOfAds (){
  var length = this.options.length
  if(this.addedKeywords === false){
    for(var x = 1; x < length; x++){
      this.newAds[x].push({
        id: x,
        headline1: 'New',

      })
    }
    this.addedKeywords = true;
  }
 },
 lengthInput: function (){

  return this.options.length

}
},
watch: {
lengthInput: function(oldlength, newLength){
  if(newLength > oldlength && this.addedKeywords != false){
    for(var x = oldLength; x < newLength; x++){
      this.newAds.push([{
        id: x,
        headline1: 'New',

      }])
    }
  }

}
}
vue.js vuejs2
1个回答
1
投票

您可以使用观察家[https://vuejs.org/v2/guide/computed.html#Watchers] TP收听数据变量的值更改并运行特定功能时steps达到指定值。您还可以创建一些flag变量,并适当设置,以防止功能得到再次触发。

© www.soinside.com 2019 - 2024. All rights reserved.