uni-app 编辑组件加载 Quill.js 错误,链接为 https://unpkg.com/quill@1.3.7/dist/quill.min.js
uni-app 编辑组件加载 Quill.js 错误,链接为 https://unpkg.com/quill@1.3.7/dist/quill.min.js
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Windows | 11 | HBuilderX |
产品分类:uniapp/App
PC开发环境操作系统:Windows
HBuilderX类型:正式
HBuilderX版本号:3.98
手机系统:Android
手机系统版本号:Android 14
手机厂商:华为
手机机型:123
页面类型:vue
vue版本:vue2
打包方式:云端
项目创建方式:HBuilderX
示例代码:
1231231
操作步骤:
23213
预期结果:
213123
实际结果:
3213123
bug描述:
213123123
5 回复
原因是近期很多地区不能正常访问 unpkg 导致的,如果问题没有解决,请参考这篇文章进行修改。https://ask.dcloud.net.cn/article/40900
如果还有疑问请继续评论
这个在editor 组件 h5 端遇到过这个,https://uniapp.dcloud.net.cn/component/editor.html#editor-组件
已解决
把index.html 指定成模版页 ,https://uniapp.dcloud.net.cn/collocation/manifest.html#h5-template
把js文件名称 和 引用 改成这样
script src="/static/quill.min.js"></script
script src="/static/image-resize.min.js"></script
在 uni-app 中加载 Quill.js 时遇到错误,可能是由于多种原因引起的。以下是一些可能的原因和解决方案:
1. 跨域问题
- 问题描述: 如果你在 uni-app 中直接通过
<script>
标签引入 Quill.js,可能会遇到跨域问题。 - 解决方案: 你可以将 Quill.js 下载到本地,然后在项目中引用本地的文件。
2. Quill.js 版本问题
- 问题描述: 你使用的 Quill.js 版本可能不兼容当前的 uni-app 版本。
- 解决方案: 尝试使用其他版本的 Quill.js,或者确保 uni-app 的版本与 Quill.js 兼容。
3. uni-app 的 web-view
组件问题
- 问题描述: 如果你在
web-view
组件中加载 Quill.js,可能会遇到一些限制。 - 解决方案: 确保
web-view
组件的配置正确,并且 Quill.js 在web-view
中能够正常运行。
4. Quill.js 依赖的 CSS 文件未加载
- 问题描述: Quill.js 需要加载相应的 CSS 文件才能正常显示编辑器。
- 解决方案: 确保在引入 Quill.js 的同时,也引入了相应的 CSS 文件。
5. uni-app 的 vue
版本问题
- 问题描述: uni-app 使用的
vue
版本可能与 Quill.js 不兼容。 - 解决方案: 尝试使用与 uni-app 兼容的 Quill.js 版本,或者调整 uni-app 的配置。
6. Quill.js 初始化问题
- 问题描述: Quill.js 在初始化时可能需要特定的配置。
- 解决方案: 确保在初始化 Quill.js 时传递了正确的配置参数。
示例代码
以下是一个在 uni-app 中加载 Quill.js 的示例:
<template>
<view>
<div id="editor"></div>
</view>
</template>
<script>
export default {
mounted() {
this.loadQuill();
},
methods: {
loadQuill() {
const script = document.createElement('script');
script.src = 'https://unpkg.com/quill@1.3.7/dist/quill.min.js';
script.onload = () => {
const quill = new Quill('#editor', {
theme: 'snow'
});
};
document.head.appendChild(script);
const link = document.createElement('link');
link.href = 'https://unpkg.com/quill@1.3.7/dist/quill.snow.css';
link.rel = 'stylesheet';
document.head.appendChild(link);
}
}
};
</script>
<style>
#editor {
height: 300px;
}
</style>