gpt4 book ai didi

javascript - ESLint 和 Vue - 如何禁止使用 `$log`?

转载 作者:行者123 更新时间:2023-12-04 15:09:45 25 4
gpt4 key购买 nike

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

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

最佳答案

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

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

关于javascript - ESLint 和 Vue - 如何禁止使用 `$log`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65434989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com