【问题标题】:how to fix "'Tagify' is declared but its value is never read" error?如何修复“'Tagify' 已声明但其值从未被读取”错误?
【发布时间】:2020-12-24 02:57:15
【问题描述】:

我正在尝试在我的项目中使用 Tagify,但要么文档不清楚如何使用它,要么我是 JS 最糟糕的人。我在我的app.js 中添加了import Tagify from '@yaireo/tagify'; 并编译它没有错误,但后来我返回到app.js 我收到了'Tagify' is declared but its value is never read 的IDE 警告,我不知道该怎么做。也在控制台 i get the Uncaught ReferenceError: Tagify is not defined报错。

另外,我在刀片文件中使用以下脚本在文本框上使用标记:

<script>
        var input = document.querySelector('textarea[name=webskills]'),
            tagify = new Tagify(input, {
                enforceWhitelist : true,
                delimiters       : null,
                whitelist        : ["The Shawshank Redemption", "The Godfather", "The Godfather: Part II", "The Dark Knight", "12 Angry Men", "Schindler's List", "Pulp Fiction",],
                callbacks        : {
                    add    : console.log,  // callback when adding a tag
                    remove : console.log   // callback when removing a tag
                }
            });
    </script>

【问题讨论】:

  • 我认为您缺少一些关于如何捆绑 app.js 以及是否/如何将其包含在页面中的细节。
  • 我像这样捆绑我的 app.js,除了标记其他一切都在工作。我也将它包含在我的页面中,例如&lt;script src="{{ asset('js/app.js') }}"&gt;&lt;/script&gt;,除了这个之外,一切都在正常工作。我想你是对的。不知道如何在我的包中包含 tagify。 window.$ = window.jQuery = require('jquery'); window.Popper = require('popper.js').default; require ('./bootstrap'); var Turbolinks = require("turbolinks"); Turbolinks.start(); import Tagify from '@yaireo/tagify';

标签: javascript tagify


【解决方案1】:

如果不使用tagify变量,则不需要tagify = new Tagify(...,只需写:

<script>
  var input = document.querySelector('textarea[name=webskills]')

  new Tagify(input, {
                enforceWhitelist : true,
                delimiters       : null,
                whitelist        : ["The Shawshank Redemption", "The Godfather", "The Godfather: Part II", "The Dark Knight", "12 Angry Men", "Schindler's List", "Pulp Fiction",],
                callbacks        : {
                    add    : console.log,  // callback when adding a tag
                    remove : console.log   // callback when removing a tag
                }
            })
</script>

您看到的这个警告可以被视为无关紧要而安全地忽略。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-10
    • 2018-09-28
    • 2018-10-05
    • 1970-01-01
    • 2020-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多