Vue3 launch-editor源码解读

若川的解读文章
据说 99% 的人不知道 vue-devtools 还能直接打开对应组件文件?本文原理揭秘: https://juejin.cn/post/6959348263547830280
尤雨溪开发的 vue-devtools 如何安装,为何打开文件的功能鲜有人知?:https://juejin.cn/post/6994289281141309476

川哥最近组织了一次源码共读活动。每周读 200 行左右的源码。感兴趣可以关注他的公众号若川视野。

准备

  1. 把川哥的文章过一遍,明确目标
  2. 学习目标:了解vue-devtools打开组件实现原理

具体操作

使用的组件

主要launch-editor-middleware和launch-editor两个库的使用

launch-editor-middleware

launch-editor-middleware中间件的主要作用调用launch-editor

源码调用

// vue3-project/node_modules/@vue/cli-service/lib/commands/serve.js
// 46行
const launchEditorMiddleware = require('launch-editor-middleware')
// 192行
before (app, server) {
   
    // launch editor support.
    // 调用launchEditorMiddleware
    app.use('/__open-in-editor', launchEditorMiddleware(() => console.log(
        `To specify an editor, specify the EDITOR env variable or ` +
        `add "editor" field to your Vue project config.\n`
    )))
    // 省略若干代码...
}
const url = require('url')
const path = require('path')
const launch = require('launch-editor')

// 根据上面的代码看出specifiedEditor传入的是个返回值为console.log()的函数
module.exports = (specifiedEditor, srcRoot, onErrorCallback) => {
   
  if (typeof specifiedEditor === 'function') {
   
    onErrorCallback = specifiedEditor// 赋值给onErrorCallback
    specifiedEditor = undefined
  }

  if (typeof srcRoot === 'function') {
   
    onErrorCallback = srcRoot
    srcRoot = undefined
  }

  // srcRoot 是传递过来的参数,或者当前node进程的目录
  srcRoot = srcRoot || process.cwd()

  // 返回中间件函数
  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
vue-quill-editor是一个可以在Vue项目中使用的富文本编辑器组件。它支持上传图片和调整图片大小的功能。为了实现这些功能,你需要安装两个插件:quill-image-drop-module和quill-image-resize-module。首先,你需要通过npm命令安装这两个插件。然后,你需要修改配置文件,以便在Vue项目中使用这些插件。具体的安装和配置步骤如下: 1. 打开终端,进入你的Vue项目所在的目录,并执行以下命令来安装quill-image-drop-module和quill-image-resize-module插件: ``` npm install quill-image-drop-module -S npm install quill-image-resize-module -S ``` 2. 在Vue2中,你需要修改配置文件。具体的修改方式可以参考插件的文档或示例代码。 3. 在Vue3中,你需要先安装vue-quill-editor组件。执行以下命令来安装vue-quill-editor: ``` npm install @vueup/vue-quill@alpha --save ``` 4. 在你的main.js文件中,导入vue-quill-editor组件,并将其注册为全局组件: ``` import { createApp } from 'vue'; import { QuillEditor } from '@vueup/vue-quill'; import '@vueup/vue-quill/dist/vue-quill.snow.css'; createApp(App) .component('QuillEditor', QuillEditor) .mount('#app'); ``` 5. 在需要使用富文本编辑器的组件中,使用<quill-editor>标签来引入vue-quill-editor组件,并传入相应的属性和事件监听: ```html <template> <quill-editor content-type='html' :content='content' :options='options' @blur='editorBlur($event)' /> </template> <script setup> import { ref } from 'vue'; let content = ref("<p>初始内容...</p>"); let options = {/* 配置选项 */} </script> ``` 以上是使用vue-quill-editor的基本步骤。希望对你有帮助!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值