Javascript 为什么在尝试将元素附加到文档时出错?

Javascript 为什么在尝试将元素附加到文档时出错?,javascript,vue.js,vuejs2,nuxt.js,Javascript,Vue.js,Vuejs2,Nuxt.js,我有自定义方法: prependCities() { if(process.client) { var locations = document.createElement("datalist"); locations.id = "locations"; var cities = this.cities; for(var i = 0; i < cities.length; i++) { var opt = cities[i];

我有自定义方法:

prependCities() {
  if(process.client) {
    var locations = document.createElement("datalist");
    locations.id = "locations";
    var cities = this.cities;
    for(var i = 0; i < cities.length; i++) {
        var opt = cities[i];
        var el = document.createElement("option");
        el.textContent = opt;
        el.value = opt;
        locations.appendChild(el);
    }​
    var body = document.getElementsByTagName("form")[0]; 
    body.insertBefore(locations, body.children[0]);
  }
}

哪里有错误?

此列中有一个不可见字符

请看这里:


此列中有一个不可见的字符

请看这里:

这对我有用。看一看:

这对我有用。看一看:

  418 |             el.value = opt;
  419 |             locations.appendChild(el);
> 420 |         }​
      |          ^
  421 |         var body = document.getElementsByTagName("form")[0]; 
  422 |         body.insertBefore(locations, body.children[0]);
  423 |       }
prependCities() {
  if(process.client) {
    var locations = document.createElement("datalist");
    locations.id = "locations";
    var cities = this.cities;
    for(var i = 0; i < cities.length; i++) {
        var opt = cities[i];
        var el = document.createElement("option");
        el.textContent = opt;
        el.value = opt;
        locations.appendChild(el);
    }
    var body = document.getElementsByTagName("form")[0]; 
    body.insertBefore(locations, body.children[0]);
  }
}
prependCities() {
  if(process.client) {
    var locations = document.createElement("datalist");
    locations.id = "locations";
    var cities = this.cities;
    for(var i = 0; i < cities.length; i++) {
        var opt = cities[i];
        var el = document.createElement("option");
        el.textContent = opt;
        el.value = opt;
        locations.appendChild(el);
    }
    var body = document.getElementsByTagName("form")[0]; 
    body.insertBefore(locations, body.children[0]);
  }
}