如何解决未在Nuxt的阈值插件中定义Chartist
我正在尝试遵循this post的建议来利用this threshold plugin,并得到“未定义Chartist”的信息。
我不确定如何在Vue / Nuxt中复制构造函数,因此我不确定这是否是我收到错误的原因,或者该职位是否不适合我想要的工作。
>这是我的代码段:
<template>
<div class="ct-chart"></div>
</template>
<script>
import Chartist from 'chartist'
import * as Threshold from 'chartist-plugin-threshold'
...
export default {
mounted() {
var threshold = Threshold()
new Chartist.Line(
'.ct-chart',...
plugins: [
Chartist.plugins.ctThreshold({
threshold: 4,}),],
解决方法
我建议您使用vue-chartist软件包,该软件包是专门为与Vue无缝工作而专门设计的。
要安装它,请运行以下命令:
npm install vue-chartist
要使其在Nuxt中工作,您应该将其作为插件添加到plugins
文件夹中。因此,例如,如果您创建一个vue-chartist.js
文件,它应该是这样的:
import Vue from 'vue'
Vue.use(require('vue-chartist'))
,然后您必须将其添加到nuxt.config.js
文件中:
plugins: ['@/plugins/vue-chartist.js']
之后,您可以通过chartist
组件使用它:
<chartist
ratio="ct-major-second"
type="Line"
:data="chartData"
:options="chartOptions" >
</chartist>
查看顶部的链接以获取更多信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。