【问题标题】:Adding class to p tags throws eslint error将类添加到 p 标签会引发 eslint 错误
【发布时间】:2020-04-06 03:33:10
【问题描述】:

我正在开发一个项目并将 Vue 集成到其中。 webpack 编译器包含 eslint 和 vues eslint。当我尝试编译代码时,我收到错误cannot read property 'replace' of undefined。每当我尝试添加具有任何属性的<p> 标记时,就会出现这种情况。查看<p class="name">John Smith</p> 下面的代码会抛出错误。如果我删除它,错误就消失了。

我没有在文件中的任何地方使用replace,所以我不确定为什么 eslint 会抛出这个错误,或者如何解决它。

组件文件

<template>
    <div v-if="committee_id > 0">
        <a
            href="#"
            class="line-btn blue"
        ><span>Return to the section's committees list</span></a>
        <h2>{{ data.title }}</h2>
        <div
            v-html="data.content"
        ></div>
        <div class="btn-cnt">
            <a
                href="#"
                class="curve-btn blue"
                @click.prevent="goBack"
            ><span>Join the committee</span></a>
        </div>
        <div class="roster detail-roster">
            <h3>Committees Roster</h3>
            <div class="row">
                <div class="col-xs-6">
                    <p class="name">John Smith</p>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import {EventBus} from '../event-bus';
    import axios      from 'axios';

    export default {
        data() {
            return {
                classArray: {
                    name: 'name',
                    title: 'title',
                },
                committee_id: 0,
                data: [],
                api_url: (API.restUrl !== undefined) ? API.restUrl : '',
            };
        },
        created() {
            EventBus.$on('committee-post-id', committee_id => {
                this.committee_id = committee_id;
                this.getCommitteePost();
            });
        },
        methods: {
            getCommitteePost: () => {
                this.$nextTick(function () {
                    axios.get(`${this.api_url + this.committee_id}`)
                         .then(({data}) => {
                             if (data.message === 'success') {
                                 this.$nextTick(function () {
                                     this.data = data;
                                 });
                             }
                         })
                         .catch(err => {});
                });
            },
            goBack: () => {

            }
        },
        name: 'section-committee'
    };
</script>

埃斯林特

module.exports = {
  "root": null,
  "globals": {
    "wp": true
  },
  "env": {
    "node": true,
    "es6": true,
    "amd": true,
    "browser": true,
    "jquery": true
  },
  'extends': [
    'plugin:vue/recommended'
  ],
  "parserOptions": {
    "ecmaFeatures": {
      "globalReturn": true,
      "generators": false,
      "objectLiteralDuplicateProperties": false,
      "experimentalObjectRestSpread": true
    },
    "ecmaVersion": 2017,
    "sourceType": "module"
  },
  "plugins": [
    "import"
  ],
  "settings": {
    "import/core-modules": [],
    "import/ignore": [
      "node_modules",
      "\\.(coffee|scss|css|less|hbs|svg|json)$"
    ]
  },
  "rules": {
    "no-console": 0
  }
}

【问题讨论】:

  • 将 ESLint 配置添加到您的问题中。
  • 谢谢,已将其添加到问题中。

标签: vue.js vuejs2 vue-component eslint


【解决方案1】:

仍然不确定发生了什么,但 linter 的解决方案是更改我的 linter 文件中的以下内容。

'extends': [
    'plugin:vue/base'
  ],

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-14
    • 2016-08-28
    • 2016-05-30
    • 2020-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多