我有自定义方法:
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]);
}
}
当我在mounted
钩子上运行此方法,然后收到错误消息:
SyntaxError:C:\ xampp \ htdocs \ newbabolo \ components \ MyForm.vue:意外字符''(420:9)
418 | el.value = opt;
419 | locations.appendChild(el);
> 420 | }
| ^
421 | var body = document.getElementsByTagName("form")[0];
422 | body.insertBefore(locations, body.children[0]);
423 | }
我有什么错误吗?
您在此列中有一个不可见的字符。
查看此处:https://jsfiddle.net/1tm5zqda/
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]);
}
}