简体   繁体   English

如何在Laravel中导入Progressbar.js?

[英]How do I import Progressbar.js in Laravel?

I'm trying to use this progress bar in Laravel 5.6. 我试图在Laravel 5.6中使用此进度条 According to Progress.js docs, you do the following: 根据Progress.js文档,您可以执行以下操作:

var ProgressBar = require('progressbar.js')

In the default assets/js/bootstrap.js file I have: 在默认的assets/js/bootstrap.js文件中,我有:

window._ = require('lodash');
window.Popper = require('popper.js').default;
window.ProgressBar = require('progressbar.js');

But I still get progressbar is undefined when I attempt to use it in the front end. 但是当我尝试在前端使用progressbar is undefined时,仍然得到progressbar is undefined Lodash & Popper are accessible. 您可以访问Lodash和Popper。

When I hover over window.ProgressBar = require('progressbar.js'); 当我将鼠标悬停在window.ProgressBar = require('progressbar.js'); in VCS, it says: 在VCS中,它说:

Could not find a declaration file for module 'progressbar.js'. 找不到模块“ progressbar.js”的声明文件。

'/Users/proevilz/sites/stream-raiders/node_modules/progressbar.js/src/main.js' implicitly has an 'any' type. “ /Users/proevilz/sites/stream-raiders/node_modules/progressbar.js/src/main.js”隐式具有“ any”类型。

Try npm install @types/progressbar.js if it exists or add a new declaration (.d.ts) file containing declare module 'progressbar.js'; 尝试npm install @types/progressbar.js如果存在)或添加一个包含declare module 'progressbar.js';的新声明(.d.ts)文件declare module 'progressbar.js';

I did what it suggested but got an error from NPM stating there is no types. 我做了它的建议,但是从NPM收到一个错误,指出没有类型。

The main.js contains: main.js包含:

module.exports = {
    // Higher level API, different shaped progress bars
    Line: require('./line'),
    Circle: require('./circle'),
    SemiCircle: require('./semicircle'),

    // Lower level API to use any SVG path
    Path: require('./path'),

    // Base-class for creating new custom shapes
    // to be in line with the API of built-in shapes
    // Undocumented.
    Shape: require('./shape'),

    // Internal utils, undocumented.
    utils: require('./utils')
};

What am I doing wrong exactly? 我到底在做什么错? Can I load this package in without explicit referencing the progressbar.js file in my HTML file? 是否可以在不显式引用HTML文件中的progressbar.js文件的情况下加载此程序包?

After helping a bit more on a stream, it looks like the issue was that it was not saved as a dev dependency, but instead as a regular dependency. 在对流进行更多帮助之后,问题似乎在于它没有保存为开发依赖项,而是保存为常规依赖项。 Moving it over in the package.json file and running npm install was the fix. 解决方法是将其移至package.json文件中并运行npm install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM