已经导入组件库,但是却说找不到

已经导入vue组件库和jQuery组件库,但是页面报错说没有找到是为什么?

img

img

img

如果你已经导入了Vue组件库和jQuery组件库(例如使用了<script>标签引入CDN),但是在页面上报出了404错误,这通常意味着浏览器无法找到所请求的资源。

以下是一些可能导致404错误的常见原因和解决方法:

  1. CDN连接错误:检查你在<script>标签中引入的组件库的CDN链接是否正确。确保链接无误,并检查网络连接是否正常。有时CDN提供商可能会发生故障或暂时不可用,这可能导致404错误。

  2. 文件路径错误:如果你通过本地文件引入组件库,确保文件路径是正确的。请检查文件路径是否与组件库文件的实际位置相匹配。

  3. 文件下载/加载错误:如果你通过本地文件引入组件库,确保你已经下载了正确版本的组件库文件,并将其放置在你的项目目录中。检查文件是否下载完整,并尝试重新下载组件库文件。

  4. 服务器配置错误:如果你使用了本地服务器(例如Webpack开发服务器)运行你的项目,请确保服务器配置正确。检查服务器是否正确设置了资源的路径和文件引用。

  5. 浏览器缓存问题:浏览器可能会缓存资源,导致之前的错误信息仍然显示。尝试清除浏览器缓存,然后刷新页面以获取最新的资源。

【相关推荐】



  • 这有个类似的问题, 你可以参考下: https://ask.csdn.net/questions/7436284
  • 这篇博客你也可以参考下:如何在vue中引入jquery
  • 除此之外, 这篇博客: vue项目中一键移除项目的jquery中的 时,其实就是在调用该类上的方法,那么对这个文件做一些修改 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
    export class Utils {
        constructor(selector) {
            this.elements = Utils.getSelector(selector);
            this.element = this.get(0);
            return this;
        }
    
        on(events, listener) {
            events.split(' ').forEach((eventName) => {
                this.each((el) => {
                    const tNEventName = Utils.setEventName(el, eventName);
                    if (!Array.isArray(Utils.eventListeners[tNEventName])) {
                        Utils.eventListeners[tNEventName] = [];
                    }
                    Utils.eventListeners[tNEventName].push(listener);
    
                    // https://github.com/microsoft/TypeScript/issues/28357
                    if (el) {
                        el.addEventListener(eventName.split('.')[0], listener);
                    }
                });
            });
    
            return this;
        }
        remove() {
            this.each((el) => {
                el.parentNode.removeChild(el);
            });
            return this;
        }
        css(css, value) {
            if (value !== undefined) {
                this.each((el) => {
                    Utils.setCss(el, css, value);
                });
                return this;
            }
            if (typeof css === 'object') {
                for (const property in css) {
                    if (Object.prototype.hasOwnProperty.call(css, property)) {
                        this.each((el) => {
                            Utils.setCss(el, property, css[property]);
                        });
                    }
                }
                return this;
            }
            const cssProp = Utils.camelCase(css);
            const property = Utils.styleSupport(cssProp);
            return getComputedStyle(this.element)[property];
        }
        static getSelector(selector, context) {
            if (selector && typeof selector !== 'string') {
                if (selector.length !== undefined) {
                    return selector;
                }
                return [selector];
            }
            context = context || document;
    
            // For performance reasons, use getElementById
            // eslint-disable-next-line no-control-regex
            const idRegex = /^#(?:[\w-]|\\.|[^\x00-\xa0])*$/;
            if (idRegex.test(selector)) {
                const el = document.getElementById(selector.substring(1));
                return el ? [el] : [];
            }
            return [].slice.call(context.querySelectorAll(selector) || []);
        }
        get(index) {
            if (index !== undefined) {
                return this.elements[index];
            }
            return this.elements;
        }
        each(func) {
            if (!this.elements.length) {
                return this;
            }
            this.elements.forEach((el, index) => {
                func.call(el, el, index);
            });
            return this;
        }
        static setEventName(el, eventName) {
            // Need to verify https://stackoverflow.com/questions/1915341/whats-wrong-with-adding-properties-to-dom-element-objects
            const elementUUId = el.eventEmitterUUID;
            const uuid = elementUUId || Utils.generateUUID();
            // eslint-disable-next-line no-param-reassign
            el.eventEmitterUUID = uuid;
            return Utils.getEventName(eventName, uuid);
        }
        static setCss(el, prop, value) {
            // prettier-ignore
            let cssProperty = Utils.camelCase(prop);
            cssProperty = Utils.styleSupport(cssProperty);
            el.style[cssProperty] = value;
        }
        static camelCase(text) {
            return text.replace(/-([a-z])/gi, (s, group1) => group1.toUpperCase());
        }
        static styleSupport(prop) {
            let vendorProp;
            let supportedProp;
            const capProp = prop.charAt(0).toUpperCase() + prop.slice(1);
            const prefixes = ['Moz', 'Webkit', 'O', 'ms'];
            let div = document.createElement('div');
    
            if (prop in div.style) {
                supportedProp = prop;
            } else {
                for (let i = 0; i < prefixes.length; i++) {
                    vendorProp = prefixes[i] + capProp;
                    if (vendorProp in div.style) {
                        supportedProp = vendorProp;
                        break;
                    }
                }
            }
    
            div = null;
            return supportedProp;
        }
        static generateUUID() {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
                // eslint-disable-next-line no-bitwise
                const r = (Math.random() * 16) | 0;
                // eslint-disable-next-line no-bitwise
                const v = c === 'x' ? r : (r & 0x3) | 0x8;
                return v.toString(16);
            });
        }
        static getEventName(eventName, uuid) {
            return `${eventName}__EVENT_EMITTER__${uuid}`;
        }
    }
    
    Utils.eventListeners = {};
    
    export default function $utils(selector) {
        return new Utils(selector);
    }


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^