当前位置: 首页 - 编程技术 - 文章正文

关于Vue使用es6模板字符串没反应的问题

xiaoqihv
错误示范

VScode发get请求的地址及参数使用单引号''包裹时,发现${this.keyWord}没有变颜色,跟字符串一个颜色,也就是没有将this.keyWord识别成变量,当成了一般字符串,发请求时带的参数问题请求不到结果

search(){this.$axios.get('https://api.github.com/search/users?q=${this.keyWord}').then(res => {console.log(res);},err => {console.log(err);})} 正确做法

将包裹字符串与模板字符串的单引号''换做倒引号``,也就是键盘左上角Esc键下面的波浪号那个键(注意要英文状态下的),可以看到模板字符串变颜色了,就可以正常使用啦

search(){this.$axios.get(`https://api.github.com/search/users?q=${this.keyWord}`).then(res => {console.log(res);},err => {console.log(err);})}
文章地址:https://wenmayi.cn/post/504.html