element ui 图片上传_nuxt打包element-ui上传阿里云oss(CDN)上字体出现跨域问题

今天打包将项目放到linux服务器上,打包项目,将打包文件放到阿里云oss(CDN),访问界面时,出现element字体跨域问题。截图如下:

c6c5339e5ab2196d3970326b63ba086a.png

苦逼一下午,终于解决了这个问题。

1.先要理解vue和nuxt的assets文件夹和static文件夹的区别,asset是会被webpack打包,

你只有将字体文件放到static就会当成静态文件直接访问,不会处理。所以我将element-ui的所以样式都放到了static文件中,如下图:

ba7f7db3eb91e5affe98620644dad05d.png

这些字体你可以在node_modules文件中element-ui/lib/theme-chalk查找

2.你需要将element-ui/lib/theme-chalk的样式全部放到assets文件中

d8fcc23775fe44c562c89f6775f59e09.png

3.在nuxt.config.js加入如下代码 /*

** Global CSS

*/

css: [

'~assets/css/theme-chalk/index.css',

],

在pluns文件中的修改element-ui.js

2350764b3a61f1e8c53feac16eb21742.png

修改如下

import Vue from 'vue'

Vue.use(require('element-ui'))

在打包如下:

a973b6d7e49d3f2eb7463c91bbedbf18.png

没有font文件夹了,然后上阿里云OSS(cdn)就不会报字体跨域问题了。

还有一个最重要的是字体样式问题,是字体的路劲。如果修改了,相对路径为 /fonts/.... 重点是多个/ 才能映射到static文件夹

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在nuxt中使用vue-quill-editor和element上传图片,您需要执行以下步骤: 1. 安装依赖: ``` npm install vue-quill-editor element-ui ``` 2. 在nuxt.config.js中配置插件: ```js plugins: [ { src: '@/plugins/vue-quill-editor', ssr: false }, { src: '@/plugins/element-ui', ssr: true } ] ``` 3. 在plugins文件夹中创建vue-quill-editor.js文件: ```js import Vue from 'vue' import VueQuillEditor from 'vue-quill-editor' // import styles import 'quill/dist/quill.core.css' import 'quill/dist/quill.snow.css' import 'quill/dist/quill.bubble.css' Vue.use(VueQuillEditor) ``` 4. 在plugins文件夹中创建element-ui.js文件: ```js import Vue from 'vue' import Element from 'element-ui' Vue.use(Element) ``` 5. 在您的组件中使用vue-quill-editor: ```vue <template> <div> <quill-editor v-model="content" :options="editorOption"></quill-editor> </div> </template> <script> export default { data() { return { content: '', editorOption: { // ... // 其他quill-editor选项 // ... imageUpload: { url: 'http://localhost:3000/upload', method: 'POST', name: 'image', headers: { Authorization: `Bearer ${this.$auth.getToken('local')}` }, withCredentials: true, callbackOK: (res) => { this.$refs.editor.quill.insertEmbed(this.quill.getSelection().index, 'image', res.url) } } } } } } </script> ``` 6. 在您的组件中使用element-ui上传文件: ```vue <template> <div> <el-upload class="avatar-uploader" action="http://localhost:3000/upload" :headers="{ Authorization: `Bearer ${this.$auth.getToken('local')}` }" :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload"> <img v-if="imageUrl" :src="imageUrl" class="avatar"> <i v-else class="el-icon-plus avatar-uploader-icon"></i> </el-upload> </div> </template> <script> export default { data() { return { imageUrl: '' } }, methods: { handleAvatarSuccess(res, file) { this.imageUrl = res.url }, beforeAvatarUpload(file) { // 验证文件类型和大小等 } } } </script> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值