为啥 IntelliJ 不断从这个 JavaScript 模板字符串中删除反引号?

     2023-03-07     303

关键词:

【中文标题】为啥 IntelliJ 不断从这个 JavaScript 模板字符串中删除反引号?【英文标题】:Why does IntelliJ keep removing backticks from this JavaScript template string?为什么 IntelliJ 不断从这个 JavaScript 模板字符串中删除反引号? 【发布时间】:2017-09-17 10:56:03 【问题描述】:

我想在我的template strings 周围加上“反引号”。

IntelliJ 每次我尝试将它们缠绕在字符串上时都会删除它们。

任何人都知道它为什么会发生以及如何解决这个问题?

我在我的 .vue 文件中添加了一个小代码 sn-p 出现问题的地方。想象一下 html、js 和 css 写在一个组件 (.vue) 文件中,由唯一的标签(模板、脚本和样式标签)分隔。 我正在使用带有 Mac OS X 10.5+ 键盘映射的德语键盘布局。

import axios from "axios";
import 'vue-animate/dist/vue-animate.min.css';

export default 
  name: 'hello',
  data () 
    return 
      msg: `Service is <strong>ONLINE</strong> and <strong>READY</strong> to operate`,
      clicked: false,
      iconURL:"./../../static/img/meditate.svg",
      meditationAction: this.activateMeditation,
      backgroundImage: "",
      room:"Bad"

    
  ,
  methods:
      activateMeditation () 
          this.clicked = !this.clicked;

          axios.get(`http://localhost:5005/$this.room/shuffle/on`).then(response => 
              console.info("SUCCESSFULLY ACTIVATED SHUFFLE");

            axios.get(`http://localhost:5005/$this.room/volume/20`).then(response => 
              console.info("SUCCESSFULLY SET VOLUME TO 20");

              axios.get("http://localhost:5005/bad/sleep/900").then(response => 
                console.info("SUCCESSFULLY SET SLEEP TIME TO 15 MINUTES");

                axios.get("http://localhost:5005/bad/playlist/med").then(response => 
                  console.info("SUCCESSFULLY SET PLAYLIST TO MED");
                  this.iconURL = "./../../static/img/stop.svg";
                  this.meditationAction = this.pausePlayback;

                  axios.get("http://localhost:5005/bad/state").then(response => 
                    console.info("SUCCESSFULLY RETRIEVED STATE");
                    console.log(response);
                    //FIXME: USE IMAGE OF CURRENT TRACK INSTEAD OF NEXT TRACK
                    this.backgroundImage = response.data.nextTrack.absoluteAlbumArtUri;
                  )
                  .catch((error)=>
                    console.log(error);
                  );

                )
                .catch((error)=>
                  console.log(error);
                );

              )
              .catch((error)=>
                console.log(error);
              );

            )
            .catch((error)=>
              console.log(error);
            );

          )
          .catch((error)=>
            console.log(error);
            this.iconURL = "./../../static/img/attention.svg";
            this.meditationAction = this.resetButton;
          );


      ,

    pausePlayback() 

      axios.get("http://localhost:5005/bad/pause").then(response => 
        console.info("SUCCESSFULLY PAUSED PLAYBACK");
        this.iconURL = "./../../static/img/meditate.svg";
        this.meditationAction = this.activateMeditation;
        this.backgroundImage = "";
      )
      .catch((error)=>
        console.log(error);
      );

    ,

    resetButton() 

      this.iconURL = "./../../static/img/meditate.svg";
      this.meditationAction = this.activateMeditation;

    



  
 * 

    box-sizing: border-box;
  

  .logo 
    max-width:50%;
  

  .svg 
    height:5em;
    z-index:100;
  

  .option .svg .st0 
    fill: white;
    stroke: white;
  

  .options__container 
    display:flex;
    justify-content: center;
    align-items: center;
    width:100%;


  

  .option 

    display:flex;
    justify-content: center;
    align-items: center;
    height:3em;
    width:3em;

    position:relative;

    background-size:cover;

    padding:3em;
    border-radius:100%;
    background-color:white;
    border-top:3px solid black;
    border-bottom:5px solid #303030;
    border-left:3px solid black;
    border-right:7px solid #303030;



    transition: all 300ms ease-in;

  

  .option__background-image 


    position:absolute;
    background-color:white;
    opacity:0.8;
    top:0;
    left:0;
    height:100%;
    width:100%;
    border-radius: 100%;
  

  .option:hover 

    border:3px solid black;

  
  <div class="hello">
    <img class="logo" src="https://upload.wikimedia.org/wikipedia/commons/1/10/Sonos_2015-Logo.png"/>
    <h2 v-html="msg"></h2>
    <div class="options__container">
      <a class="option" v-on:click="meditationAction" v-bind:class="'animated flash' : clicked" :style="backgroundImage: 'url(' + backgroundImage +')'" >
        <div class="option__background-image" ></div>
        <img class="svg" :src=iconURL>
      </a>
    </div>
  </div>

【问题讨论】:

我看这个 gif 越多,我就越不明白发生了什么。请您提供原始代码 sn-p (作为文本)并描述要重复的步骤吗?你的系统键盘布局是什么? 我已经为我正在处理的组件添加了代码 sn-p 并添加了一些描述以进一步解释内容结构。我希望这会有所帮助。 那么,您的代码中有axios.get(http://localhost:5005/$this.room/shuffle/on).then(response =&gt; ,并试图用反引号包围“localhost:5005/$this.room/shuffle/on”?或者,尝试用反引号替换引号?要么?你的键盘布局是什么? 是的,我尝试用反引号环绕 "localhost:5005/$this.room/shuffle/on"。但是用反引号替换双引号也不起作用。我正在使用 QWERTZ 键盘布局。 可能是youtrack.jetbrains.com/issue/WEB-21750问题;请关注它以获取更新 【参考方案1】:

禁用插入对引用选项是一个不好的解决方法,解决此问题的更好方法是创建带有反引号的实时模板。

只需转到首选项 -> 编辑器 -> 实时模板,使用包含 `` 的快捷词(我的形式是 tpl)创建一个自定义模板,然后在代码中使用它只需键入 tpl+ Tab 键并完成

【讨论】:

【参考方案2】:

另一种解决方法是在另一个位置写一个反引号并将其复制/粘贴到模板周围。

【讨论】:

【参考方案3】:

我也有同样的问题。我通过禁用 Preferences -> Editor -> General -> Smart Keys 中的“插入对引号”选项来解决它。

当然,它禁止插入所有类型的引号,包括单引号和双引号。这是一个临时的解决方法,但我个人宁愿实际上能够使用 JS 的模板字符串,尽管每次都必须输入一对引号。

【讨论】:

似乎是目前最好的解决办法。谢谢:) 在 ES6 或 7 中实现正确的字符串格式函数是一个更简单的解决方法。python 方法如何调用每个字符串的内置格式函数。这是格式化字符串的最快方法,因为如果您想使用格式化,您无需更改任何内容。

intellij格式化java和xml

  使用Intellij的这段时间,一直在寻找一些技巧,不断提高对它的熟练度。接下来告诉大家一个小秘密,带大家体验一下Intellij半自动格式化代码的快感。那要使用这个功能还得安装一个插件--EclipseCodeFormatter,这个可以从Intelli... 查看详情

为啥刷新 Maven 存储库对于 IntelliJ 来说还不够?

】为啥刷新Maven存储库对于IntelliJ来说还不够?【英文标题】:WhyrefreshofMavenrepositoryisnotenoughforIntelliJ?为什么刷新Maven存储库对于IntelliJ来说还不够?【发布时间】:2021-02-2410:14:57【问题描述】:我在一些测试中遇到了NoClassDefFoundEr... 查看详情

为啥 IntelliJ 中的一些 maven 项目是灰色的?

】为啥IntelliJ中的一些maven项目是灰色的?【英文标题】:WhyaresomemavenprojectsinIntelliJgrayedout?为什么IntelliJ中的一些maven项目是灰色的?【发布时间】:2017-08-1716:34:24【问题描述】:为什么IntelliJ中的一些maven项目是灰色的?【问题... 查看详情

Intellij 不断编译 TypeScript(非常慢) - 如何阻止这种行为?

】Intellij不断编译TypeScript(非常慢)-如何阻止这种行为?【英文标题】:IntellijconstantlycompilesTypeScript(veryslow)-Howtostopthisbehavior?【发布时间】:2017-03-2623:28:18【问题描述】:我正在将Angular1.x项目从vanillaJS迁移到TypeScript。但是,我... 查看详情

IntelliJ 文件掩码不适用于简单的排除文件模式!为啥?

】IntelliJ文件掩码不适用于简单的排除文件模式!为啥?【英文标题】:IntelliJFilemasknotworkingonsimpleexcludingfilepattern!Why?IntelliJ文件掩码不适用于简单的排除文件模式!为什么?【发布时间】:2016-07-1517:21:30【问题描述】:关注这个... 查看详情

为啥 df.limit 在 Pyspark 中不断变化?

】为啥df.limit在Pyspark中不断变化?【英文标题】:Whydoesdf.limitkeepchanginginPyspark?为什么df.limit在Pyspark中不断变化?【发布时间】:2016-05-1019:10:56【问题描述】:我正在从一些数据框df中创建一个数据样本rdd=df.limit(10000).rdd这个操作... 查看详情

为啥这会不断从 Heroku/Parse 快速返回错误“找不到对象”?

】为啥这会不断从Heroku/Parse快速返回错误“找不到对象”?【英文标题】:Whydoesthiskeepreturningerror"Objectnotfound"fromHeroku/Parseinswift?为什么这会不断从Heroku/Parse快速返回错误“找不到对象”?【发布时间】:2017-04-1414:50:44【... 查看详情

为啥我不断收到这个受诅咒的 SQL*Plus 无效标识符错误?

】为啥我不断收到这个受诅咒的SQL*Plus无效标识符错误?【英文标题】:WhydoIkeepgettingthiscursedSQL*Plusinvalididentifiererror?为什么我不断收到这个受诅咒的SQL*Plus无效标识符错误?【发布时间】:2011-04-1720:41:27【问题描述】:当我尝试... 查看详情

从 Spotify API 交换访问令牌的代码时,为啥我不断收到 400 错误请求错误?

】从SpotifyAPI交换访问令牌的代码时,为啥我不断收到400错误请求错误?【英文标题】:WhydoIkeepgettinga400BadRequestErrorwhenexchangingcodeforaccesstokenfromSpotifyAPI?从SpotifyAPI交换访问令牌的代码时,为什么我不断收到400错误请求错误?【发... 查看详情

通过使用过滤器功能反应从数组中删除项目,为啥uuid不断变化?

】通过使用过滤器功能反应从数组中删除项目,为啥uuid不断变化?【英文标题】:Reactremoveitemfromarraybyusingfilterfunction,whydoestheuuidkeepschanging?通过使用过滤器功能反应从数组中删除项目,为什么uuid不断变化?【发布时间】:2021-12-... 查看详情

为啥这个 Int Value 在设置后会不断返回? [罗布洛克斯工作室]

】为啥这个IntValue在设置后会不断返回?[罗布洛克斯工作室]【英文标题】:WhydoesthisIntValuekeepcomingbackafteritisset?[RobloxStudio]为什么这个IntValue在设置后会不断返回?[罗布洛克斯工作室]【发布时间】:2022-01-0522:20:27【问题描述】:... 查看详情

IntelliJ 不断索引,当 src 文件处于焦点时

】IntelliJ不断索引,当src文件处于焦点时【英文标题】:IntelliJconstantlyindexing,whensrcfileisinfocus【发布时间】:2020-12-0616:33:43【问题描述】:我有一个奇怪的intellij行为。只要我关注像*.j​​ava这样的src文件,它就会不断地尝试重新... 查看详情

为啥 Android Studio 不断切换“语言级别”?

】为啥AndroidStudio不断切换“语言级别”?【英文标题】:WhydoesAndroidStudiokeeptoggling`languageLevel`?为什么AndroidStudio不断切换“语言级别”?【发布时间】:2018-12-0412:44:10【问题描述】:很多时候,当我查看使用AndroidStudio构建的Androi... 查看详情

为啥 IntelliJ 找不到正确的 WebServlet 类?

】为啥IntelliJ找不到正确的WebServlet类?【英文标题】:Whycan\'tIntelliJfindthecorrectWebServletclass?为什么IntelliJ找不到正确的WebServlet类?【发布时间】:2016-10-2021:14:20【问题描述】:我是IntelliJ和Maven的新手。我正在编写一个将使用H2数... 查看详情

为啥 IntelliJ 建议将调用链转换为序列?

】为啥IntelliJ建议将调用链转换为序列?【英文标题】:WhydoesIntelliJsuggesttoconvertacallchainintoaSequence?为什么IntelliJ建议将调用链转换为序列?【发布时间】:2019-02-2206:59:49【问题描述】:假设以下Kotlin示例将源集src映射到目标集dst... 查看详情

为啥这么红? IntelliJ 似乎认为无法找到/解决每个声明/方法

】为啥这么红?IntelliJ似乎认为无法找到/解决每个声明/方法【英文标题】:Whysored?IntelliJseemstothinkeverydeclaration/methodcannotbefound/resolved为什么这么红?IntelliJ似乎认为无法找到/解决每个声明/方法【发布时间】:2012-07-2220:17:00【问... 查看详情

为啥 IntelliJ 在远程调试时跳过断点

】为啥IntelliJ在远程调试时跳过断点【英文标题】:WhyisIntelliJskippingbreakpointswhileremotelydebugging为什么IntelliJ在远程调试时跳过断点【发布时间】:2015-05-2202:25:24【问题描述】:有人要求我调试安装在ApacheKaraf(OSGi)中的Java应用程序... 查看详情

为啥 Intellij 在 pom.xml 中找不到任何 Maven 依赖项?

】为啥Intellij在pom.xml中找不到任何Maven依赖项?【英文标题】:WhyIntellijdonotfindanyMavendependenciesinpom.xml?为什么Intellij在pom.xml中找不到任何Maven依赖项?【发布时间】:2019-12-2212:48:06【问题描述】:我刚刚在笔记本电脑上下载了Intell... 查看详情