【问题标题】:Library Hashids import in vue.js not workingvue.js 中的库哈希导入不起作用
【发布时间】:2019-01-21 18:39:54
【问题描述】:

我似乎无法让库 hashids 与 vue.js 一起使用

我想如何使用它的首选方法是:

<template>
    <div class="container">
        {{ hashids.encode('1') }}
    </div>
</template>

<script>
const Hashids = require("hashids")

export default {
    data () {
        return {
            Hashids: Hashids,
        }
    },

}
</script>

【问题讨论】:

  • 你试过{{ Hashids.encode('1') }} ??
  • 感谢您的评论。刚试了一下。它返回错误“[Vue warn]: Error in render:”TypeError: _vm.Hashids.encode is not a function”

标签: javascript vue.js vuejs2 vue-component hashids


【解决方案1】:

尝试在挂载的钩子中初始化Hashid,如:

<template>
    <div class="container">
        {{ Hashids.encode('1') }}
    </div>
</template>

<script>
  const Hashids = require("hashids")

  export default {
    data() {
      return {
        Hashids: null,
      }
    },
    mounted() {
        this.Hashids = new Hashids.default()
    }

  }
</script>

这让它成功了!

【讨论】:

  • 它会说:“TypeError:Hashids 不是构造函数”。也许“const Hashids = require("hashids")” 部分是错误的?
  • @WoutervanErp new Hashids.default() 解决了这个问题吗?
猜你喜欢
  • 1970-01-01
  • 2017-10-20
  • 1970-01-01
  • 2012-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多