【问题标题】:Vs code Quotes being formatted to new line causing file to be a stringVs代码引号被格式化为新行导致文件成为字符串
【发布时间】:2021-10-04 16:11:30
【问题描述】:

我正在尝试格式化我的文件,但引号被添加到新行并将我的文件转换为字符串。 prettier / vscode 中是否有设置不将引号格式化到新行或忽略此引号将整个文件转换为字符串

例如:

@click="
   createStudent();
   $emit('hide-modal');
   makeToast('success');
"
// anything below this quote on a new line will make the rest of the file appear as a string.

Eslint 文件:


module.exports = {
  root: true,
  extends: [
    'plugin:vue/essential',
    'plugin:prettier/recommended',
    'eslint:recommended'
  ],
  parserOptions: {
    parser: 'babel-eslint',
    sourceType: 'module'
  },
  rules: {
    quotes: [2, 'single', { avoidEscape: true, allowTemplateLiterals: true }],
    'prettier/prettier': [
      'warn',
      {
        singleQuote: true,
        semi: false
      }
    ]
  }
}

【问题讨论】:

    标签: vue.js eslint prettier


    【解决方案1】:

    您需要在每个函数调用的末尾包含分号

    <button
      @click="
        call1();
        call2();
      "
    >
      test me
    </button>
    

    Example


    另一种处理方法(我认为是更好的方法)是创建一个调用所有三个函数的方法。

    <template>
        <button @click="blahBlahClickHandler"> press me </button>
    </template>
    
    <script>
    export default {
        methods:{
            blahBlahClickHandler(){
                this.createStudent();
                this.$emit('hide-modal');
                this.makeToast('success');
            }
        }
    }
    </script>
    

    【讨论】:

    • 在函数中添加分号时,它仍然会将第二个"以下的所有内容转换为字符串
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-12
    • 1970-01-01
    相关资源
    最近更新 更多