vue3+uniapp的H5端集成百度ueditor

试了一天怎么都不行,卡一天,今天终于集成上去了,做个记录分享一下。最后参考
1、https://github.com/HaoChuan9421/vue-ueditor-wrap#readme

2、https://github.com/fex-team/ueditor
完成了集成。

总结:
1、npm引入

# vue-ueditor-wrap v3 仅支持 Vue 3
npm i vue-ueditor-wrap@3.x
# 或者
yarn add vue-ueditor-wrap@3.x

2、解压资源包放到静态目录下面(上面第一个链接里面有下载链接,这里我不放了,不会)

3、main.js入口文件引入

import App from './App'
import {
  createPinia
} from 'pinia'
import VueUeditorWrap from 'vue-ueditor-wrap'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import pinia from './common/data_templates/pinia.js'
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false

App.mpType = 'app'
const app = new Vue({
  ...App
})
app.use(VueUeditorWrap)
app.$mount()
// #endif

// #ifdef VUE3
import {
  createSSRApp
} from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  app.use(VueUeditorWrap)
  app.use(pinia)
  return {
    app
  }
}
// #endif

4、在index.html预加载script文件

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <script>
      var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
        CSS.supports('top: constant(a)'))
      document.write(
        '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
        (coverSupport ? ', viewport-fit=cover' : '') + '" />')
    </script>
    <!--preload-links-->
    <!--app-context-->
    <!-- 加载编辑器源码文件 -->
    <script type="text/javascript" src="/static/utf8-jsp/ueditor.all.js"></script>
    <!-- 加载配置文件 -->
    <script type="text/javascript" src="/static/utf8-jsp/ueditor.config.js"></script>
    <title></title>
  </head>
  <body>
    <div id="app"><!--app-html-->
    </div>
    <script type="module" src="/main.js"></script>
    <script type="text/javascript">
      var ue
    </script>
    <style>
      #app {
        width: 100vw;
        height: 100vh;
      }
    </style>
  </body>
</html>

5、组件中使用,注意一定要配置静态资源路径,路径不要写错了

<template>
  <view id="content">
    <vue-ueditor-wrap style="height: 50vh;width: 85vw;" @ready="editorReady" v-model="msg" :config="editorConfig"
      class="editor" id="editor" editor-id="editor" :initialFrameWidth="800" :initialFrameHeight="800"
      :editorDependencies="['ueditor.config.js','ueditor.all.js']" />
    <view class="func">
      <func_area></func_area>
    </view>
  </view>
</template>

<script setup>
  import {
    nextTick,
    onMounted,
    ref
  } from 'vue'
  import func_area from './func_area.vue'

  const msg = ref('<h2>Hello World!</h2>')
  const editorConfig = ref({
    UEDITOR_HOME_URL: '/static/utf8-jsp/' //静态资源文件夹
  })

  const editorReady = (editorInstance) => {
    console.log('UEditor is ready:', editorInstance, UE)

  }

  onMounted(() => {
    nextTick(() => {
      if (UE) {
        let s = UE.getUEBasePath()
      }
    })
  })
</script>

<style scoped>
  @import url('../../static/css/common.css');

  #content {
    width: 85vw;
    height: 80vh;

    .editor {
      height: 50vh;
      border-bottom: 1px solid red;
      width: 85vw;
      overflow: hidden;
    }

    .func {
      height: 30vh;
      width: 85vw;
    }
  }
</style>

6、如果编译后没出来,可以尝试重启hbuild

7、最后效果图

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Vue3+uni-app实现微信小程序登录流程主要分为以下步骤: 1. 在uni-app项目中安装并引入微信小程序登录插件(如wxlogin),在main.js中初始化并配置插件参数。 2. 创建一个登录页面,该页面包含点击按钮触发微信登录的操作,可以通过uni.login()方法调用微信小程序登录接口获取code。 3. 接收到微信小程序登录接口返回的code后,将code发送给后服务器,后服务器将code和小程序的App ID以及App Secret发送给微信服务器进行登录凭证校验,获取到session_key和openid。 4. 服务器根据openid和session_key生成一个自定义的token,返回给前。 5. 前将token保存在本地,使用uni.setStorage()方法进行存储,以便后续的登录状态维持和接口请求验证。 6. 在需要登录验证的页面或组件中,通过uni.getStorage()方法获取本地存储的token,并将token添加到请求头中,发送给后服务器进行接口请求。 7. 后服务器接收到带有token的请求,对token进行校验和解析,验证token是否有效,从而确保用户的登录状态。 总结:通过以上步骤,实现了Vue3+uni-app微信小程序的登录流程。用户通过点击按钮触发微信小程序登录接口,后服务器校验登录凭证,生成token并返回给前,前保存token并在请求接口时携带token进行验证,保证了用户的登录状态和接口访问权限的安全性。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值