如何在Vue模板中禁止控制台日志?

qxsslcnc  于 2023-04-07  发布在  Vue.js
关注(0)|答案(1)|浏览(171)

$log的来源:

Vue.prototype.$log = console.log

禁止的地方:

<template>
  <!-- Place 1 -->
  <div @click="$log">
    <!-- Place 2 -->
    {{ $log }}
    <!-- Place 3 -->
    {{ $log('foo') }}
  </div>
</template>

<script>
import Vue from 'vue'

// Place 4
Vue.prototype.$log('foo')

export default {
  created() {
    // Place 5
    this.$log('foo')
  },
}
</script>

一些可能有帮助的其他信息:

vi4fp9gy

vi4fp9gy1#

在深入研究了no-restricted-syntaxvue/no-restricted-syntax规则和AST s之后,我终于得到了这个工作,下面是工作规则:

{
  rules: {
    'no-restricted-syntax': [
      'error',
      {
        selector: '[name=$log]',
        message: "Using '$log' is not allowed.",
      },
    ],
    'vue/no-restricted-syntax': [
      'error',
      {
        selector: '[name=$log]',
        message: "Using '$log' is not allowed.",
      },
    ],
  },
}

相关问题