如何在Vue模板中禁止控制台登录



$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>

一些可能有帮助的附加信息:

  • ESLint-如何限制this的属性
  • 无限制语法
  • vue/no受限语法

在深入研究了no-restricted-syntaxvue/no-restricted-syntax规则和ASTs之后,我终于完成了这项工作,以下是工作规则:

{
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.",
},
],
},
}

最新更新