推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
spaceprogram

为什么字符串使用${变量}无法正确读取

  •  
  •   spaceprogram · Apr 25, 2018 · 3556 views
    This topic created in 2965 days ago, the information mentioned may be changed or developed.

    使用 WebStorm 工具写 Vue,一个项目代码 authorName(val) { const _this = this; if (this.authorName) { this.$http({ url: https://xxxx.org/api/v1/user/${val}, method: 'get' }) .then((res) => { console.log(res); _this.userInfo = res.data.data; _this.loading = false; }) .catch((res) => { console.log('SideSec.vue :', res); }); } } url: https://xxxx.org/api/v1/user/${val},能正确将 val 拼接起来。 另一个项目 created() { console.log(this.$route.path); const _url = 'https://xxxx.org/api/v1${this.$route.path}; this.$http({ url: _url, method: "get" }) 则控制台报错 https://xxxx.org/api/v1$%7Bthis.$route.path%7D 404 (Not Found),字符串没有正确拼接。请问大佬们这是什么原因

    spaceprogram
        1
    spaceprogram  
    OP
       Apr 25, 2018
    卧槽,搞定了,原来是要用`而不是'
    jessie0717
        2
    jessie0717  
       Apr 26, 2018
    就你这个排版,我回这一句话已经相当过分了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1397 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 16:51 · PVG 00:51 · LAX 09:51 · JFK 12:51
    ♥ Do have faith in what you're doing.