vue中用深拷贝 this.points = []; this.init(this.routes); setTimeout(() => { // this.points = []; this.routes=JSON.parse(JSON.stringify(this.array));; this.init(this.routes); console.log("888",this.routes); },30000);出错Unnecessary semicolon no-extra-semi
时间: 2024-02-14 19:26:26 浏览: 25
这个错误是因为代码中有多余的分号。在你的代码中,第5行和第10行的分号是多余的,可以将它们删除掉。修正后的代码如下所示:
```javascript
this.points = [];
this.init(this.routes);
setTimeout(() => {
// this.points = [];
this.routes = JSON.parse(JSON.stringify(this.array));
this.init(this.routes);
console.log("888", this.routes);
}, 30000);
```
请注意,删除多余的分号不会影响代码的功能,但会提高代码的可读性。
相关问题
<img :src="img"> 再赋值 this.img = "../../img/dog.png" 这样可以吗
可以的。Vue.js中的`:src`是一个动态绑定的属性,可以通过`v-bind`或者简写的冒号语法来绑定一个变量。因此,您可以在Vue组件的`data`选项中定义一个名为`img`的变量,并在组件中使用`:src="img"`来动态绑定图片路径。在需要修改图片路径时,只需要在Vue实例中使用`this.img`来更新该变量的值即可。
例如,您可以这样定义Vue组件:
```
<template>
<div>
<img :src="img">
</div>
</template>
<script>
export default {
data() {
return {
img: "../../img/dog.png"
}
},
methods: {
updateImg() {
this.img = "../../img/cat.png";
}
}
}
</script>
```
在上面的示例中,我们定义了一个名为`img`的变量,并在组件中使用`:src="img"`来动态绑定图片路径。在`updateImg`方法中,我们可以通过`this.img`来修改图片路径,从而更新显示的图片。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.2.47/vue.cjs.js"></script> <script src="../../../vue.config.js"></script> </head> <body> <div id="app"> <p>{{message}}</p> </div> <script> import Vue from 'vue' var app=new Vue({ el : '#app', data : { message : 'hello world' }, template:'<div>{{message}}</div>', created () { this.getIndexHtml() }, methods:{ getIndexHtml() { fetch('index.html') .then(res=>res.text()) .then(html=>{ this.index.Html = html }) } } }) </script> </body> </html>打开网页以后页面没有进行vue渲染
在你的代码中,有两个问题:
1. 在浏览器中无法直接使用 `import` 语法,需要使用 `script` 标签来引入 Vue 库,或者使用打包工具将代码打包成浏览器可识别的代码。因此,你需要将 `import Vue from 'vue'` 改成 `var Vue = window.Vue` 或者引入 Vue 库的 `CDN` 地址。
2. 在 Vue 3.x 版本中,不再支持使用 `template` 属性直接定义模板,需要使用 `render` 函数或者 `.vue` 单文件组件的方式来定义模板。因此,你需要将 `template` 属性的值改成 `render` 函数。
下面是修改后的代码:
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/3.2.47/vue.cjs.js"></script>
<script src="../../../vue.config.js"></script>
</head>
<body>
<div id="app">
<p>{{message}}</p>
</div>
<script>
var Vue = window.Vue // 或者使用 Vue 的 CDN 地址来引入 Vue 库
var app=new Vue({
el : '#app',
data : {
message : 'hello world'
},
render(h) { // 使用 render 函数来定义模板
return h('div', this.message);
},
created () {
this.getIndexHtml()
},
methods:{
getIndexHtml() {
fetch('index.html')
.then(res=>res.text())
.then(html=>{
this.index.Html = html
})
}
}
})
</script>
</body>
</html>
```
注意:由于你的代码中还涉及到 `vue.config.js` 文件,因此你需要确认这个文件是否存在并且正确引入。