【问题标题】:Vue watch syntax ${somevariable}. Could someone please explain?Vue 监视语法 ${somevariable}。有人可以解释一下吗?
【发布时间】:2022-03-03 23:23:33
【问题描述】:

How can I use window size in Vue? (How do I detect the soft keyboard?)

上面的链接是一个很好的答案,但我不明白这个 (`) 标记是什么以及为什么传入 newHeight、oldHeight 的值。还有为什么观察程序中的这种语法 ${somevariable} 有效。

windowHeight(newHeight, oldHeight) 这个.txt = it changed to ${newHeight} from ${oldHeight}; ...

【问题讨论】:

    标签: vuejs2 watch


    【解决方案1】:

    “反引号”语法不是 Vue 特有的,但它是一种称为 模板文字 的 javascript 语言功能。不过这很容易:当您编写这样的字符串时:

    const what = "world";
    const salutation = `Hello ${what}`;
    

    salutation 的值将是“Hello world”。计算表达式时,解释器将${what}what 变量的实际内容交换。

    您可以了解更多关于template literals on MDN的信息。

    在链接的答案中,它被用作一种简单的调试方法来显示正在发生的事情。

    【讨论】:

    • 感谢 Pongi。很好的解释。
    猜你喜欢
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 2011-11-22
    • 2016-12-12
    相关资源
    最近更新 更多