该示例在js小提琴中有效,但在自制页面中无效

戴维·J。

这个js-fiddle示例正在正常工作:

https://jsfiddle.net/qf089a0a/51/

但是,当我尝试自行加载该示例时,即使在js小提琴示例中,下拉菜单也没有显示任何内容(尝试在输入框中输入“无线”)。

这是我的html:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.18/vue.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

  </head>
  <body>
    <div id="app">

      <input v-model="offer.tags"></input>
      <select>
        <option v-for="(key, value) in offer.units" v-bind:value="offer.units">
          {{ key }}
        </option>
      </select>
    </div>
  </body>

        <script src="./js/app.js"></script>
</html>

这是js:

var protocol = {
  "wireless": {
    "units": {
      "bandwidth": "bit/s, Mb/s, Gb/s",
      "distance": "kilometers, miles"
    },
    "children": [],
  }

};

var vm = new Vue({
  el: '#app',
  data: {
    offer: {
      tags: '',
      units: {}
    },
    protocol: protocol
  },
  watch: {
    'offer.tags': {
      handler: function() {
        var tagList = this.offer.tags.split(',');
        console.log(tagList);

        for (var i = 0; i < tagList.length; i++) {
          console.log(tagList[i]);
          try {
            var unitsObj = this.protocol[tagList[i]]["units"];
            var unitKeys = Object.keys(unitsObj);

            for (var i = 0; i < unitKeys.length; i++) {

              if (!unitsObj[unitKeys[i]]) {
                console.log("updating units");
                // update dict only if it doesn't already contain key
                this.offer.units[unitKeys[i]] = unitsObj[unitKeys[i]];
              }

              this.offer.units[unitKeys[i]] = unitsObj[unitKeys[i]];
            }
            console.log(this.offer.units);
          } catch (e) {
            return true
          }
        }
      }
    }
  }
});

关于可能是什么问题的任何想法?

这是控制台在脱机版本中输出的内容-与联机版本相同:

    Array [ "wireless" ]
app.js:27:9
    wireless
app.js:30:11
    Object { bandwidth: "bit/s, Mb/s, Gb/s", distance: "kilometers, miles", 1 more… }

因此,显然字典正在按我的期望进行更新。

Sharath Bangera

问题是您使用的Vue JS的版本。您在这里提到的那个是不同的,而您在jsfiddle中使用的那个是不同的。

请删除此处提到的一个,然后添加以下内容。

<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/vue.js"></script>

它将正常工作。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

代码在JS小提琴上有效,但在我的网站上无效

CSS Calc返回0,但在我的小提琴中有效

三个 js - JSON 加载程序在示例中有效但在我的代码中无效?

为什么该程序在Python 2.7.6中有效,但在Python 3中无效?

解构错误对象在Chrome中有效,但在Firefox中无效。该怎么办?

.join()在一个示例中有效,但在另一个示例中无效

orphanRemoval在PostgreSQL中有效,但在hsqldb中无效

函数在查询中有效,但在约束中无效

Scrapy 在 shell 中有效,但在代码中无效

代码在终端中有效,但在脚本中无效

WritePrivateProfileString 在 main 中有效但在函数中无效

在TypeScript中创建GUID-函数在JS中有效,但在TS中无效

QUERY函数在示例工作表中有效,但在具有相同公式的新工作表中无效

mysql查询在phpmyadmin中有效,但在node.js中无效

AJAX在jQuery中有效,但在香草JS中无效

Http 请求在 PostMan 中有效,但在 JS 中无效

Api request 在 swagger 和 postman 中有效,但在 js 中无效(使用 axios)

无法在页面中显示此小提琴

React JS小提琴中的API调用

如何结合小提琴中的html,js和css

日期选择器(.js)在HTML编辑器中不起作用,但在小提琴中起作用

curve()在第一个示例中有效,但在第二个示例中无效,但是它们看起来相同。为什么?

为什么此代码在控制台中有效,但在页面加载时无效?

Cognito Auth 在 Prod 中有效,但在本地无效

更新集命令在 Access 中有效,但在带有 @parameters 的 Visual Studio 中无效

对齐问题(js小提琴)

JS 和 Bootstrap 在 Codepen 中有效,但在本地打开时无效

AppActivate在Excel 2007中有效,但在2010年中无效

Boost union在1.67中无效,但在1.61中有效。为什么?