当前位置: 首页 > news >正文

建盏公司官方网站厦门外贸商城网站建设

建盏公司官方网站,厦门外贸商城网站建设,一级a做爰片视频免费观看网站,自建网站怎么做推广使用vditor 1 下载npm包 npm i vditor2 新建一个编辑器组件&#xff0c;对vditor进行封装 注意哦这里有三个主题 let theme ‘classic’ 指的是编辑器的颜色 let contentTheme ‘light’ 指的是markdown文档的颜色 let codeTheme ‘github’ 指的是代码块的颜色 <t…

使用vditor

1 下载npm包

npm i vditor

2 新建一个编辑器组件,对vditor进行封装

注意哦这里有三个主题

let theme = ‘classic’   指的是编辑器的颜色

let contentTheme = ‘light’   指的是markdown文档的颜色

let codeTheme = ‘github’   指的是代码块的颜色

<template><div class="vditor-container"><div ref="editorRef" class="vditor-editor"></div></div>
</template><script setup>
import { ref, onMounted, onBeforeUnmount, watch } from 'vue'
import Vditor from 'vditor'
import 'vditor/dist/index.css'const props = defineProps({modelValue: { type: String, default: '' },placeholder: { type: String, default: '请输入内容...' },height: { type: [Number, String], default: '100%' },theme: { type: String, default: 'classic' }, // 'classic' | 'dark'toolbar: { type: Array, default: () => ['headings', 'bold', 'italic', 'strike', 'link', '|','list', 'ordered-list', 'check', 'outdent', 'indent', '|','quote', 'line', 'code', 'inline-code', 'insert-before', 'insert-after', '|','upload', 'table', '|', 'undo', 'redo', '|', 'edit-mode', 'both', 'preview', 'fullscreen']}
})const emit = defineEmits(['update:modelValue', 'init', 'focus', 'blur'])const editorRef = ref(null)
let vditorInstance = null// 初始化 Vditor
const initVditor = () => {const systemTheme = localStorage.getItem('theme');let theme = 'classic'let contentTheme = 'light'let codeTheme = 'github'if(systemTheme === 'dark') {theme = 'dark'contentTheme = 'dark'//  github-dark nordcodeTheme = 'github-dark'}vditorInstance = new Vditor(editorRef.value, {height: props.height,theme: theme,preview: {theme: {current: contentTheme},hljs: {defaultLang: 'html',style: codeTheme,lineNumber: true,langs: ["vue","mermaid", "echarts", "mindmap", "plantuml", "abc", "graphviz", "flowchart", "apache","js", "ts", "html","markmap",// common"properties", "apache", "bash", "c", "csharp", "cpp", "css", "coffeescript", "diff", "go", "xml", "http","json", "java", "javascript", "kotlin", "less", "lua", "makefile", "markdown", "nginx", "objectivec", "php","php-template", "perl", "plaintext", "python", "python-repl", "r", "ruby", "rust", "scss", "sql", "shell","swift", "ini", "typescript", "vbnet", "yaml","ada", "clojure", "dart", "erb", "fortran", "gradle", "haskell", "julia", "julia-repl", "lisp", "matlab","pgsql", "powershell", "sql_more", "stata", "cmake", "mathematica",// ext"solidity", "yul"]},},placeholder: props.placeholder,toolbar: props.toolbar,cache: { enable: false }, // 禁用缓存after() {vditorInstance.setValue(props.modelValue)emit('init', vditorInstance)},input: (value) => {emit('update:modelValue', value)},focus: () => emit('focus'),blur: () => emit('blur')})
}// 监听主题变化
watch(() => props.theme, (newTheme) => {if (vditorInstance) {vditorInstance.setTheme(newTheme)}
})// 监听内容变化(外部修改)
watch(() => props.modelValue, (newVal) => {if (newVal !== vditorInstance?.getValue()) {vditorInstance.setValue(newVal)}
})onMounted(() => {initVditor()
})onBeforeUnmount(() => {if (vditorInstance) {vditorInstance.destroy()vditorInstance = null}
})// 暴露方法给父组件
defineExpose({getVditor: () => vditorInstance,getValue: () => vditorInstance?.getValue(),setValue: (value) => vditorInstance?.setValue(value),focus: () => vditorInstance?.focus(),blur: () => vditorInstance?.blur()
})
</script><style scoped>
.vditor-container {width: 100%;
}
.vditor-editor {width: 100%;
}
</style>

3 使用编辑器

<template><div><h1>Vditor 编辑器示例</h1><button @click="toggleTheme">切换主题</button><button @click="getEditorContent">获取内容</button><VditorEditorv-model="content":theme="theme":height="600"@init="onEditorInit"/></div>
</template><script setup>
import { ref } from 'vue'
import VditorEditor from "@/components/VditorEditor/VditorEditor.vue";const content = ref('# Hello Markdown!\n\n试试输入 **Markdown** 语法。')
const theme = ref('classic') // 'classic' 或 'dark'
const editorInstance = ref(null)const toggleTheme = () => {theme.value = theme.value === 'classic' ? 'dark' : 'classic'
}const onEditorInit = (editor) => {editorInstance.value = editorconsole.log('编辑器初始化完成', editor)
}const getEditorContent = () => {alert(content.value || '无内容')
}
</script>

这样你的项目就继承了代码编辑器喽

http://www.dtcms.com/a/503783.html

相关文章:

  • 多模态RAG进阶:基于GPT-4V+LangGraph的下一代智能体系统完全指南
  • 自己在电脑上建文档做网站怎么做宝塔面板 wordpress制作网页
  • Docker核心揭秘:轻量级虚拟化的革命
  • 网站首页新世纪建设集团有限公司安阳贴吧论坛
  • 网站不备案可以做百度竞价吗做网站过程视频
  • 计算机网络5
  • 【论文笔记】李飞飞 世界模型RTFM
  • 微信小程序开发哪个好优化关键词排名工具
  • Text2SQL与工作流实现:让数据库查询变得轻松又高效
  • 【Android】浅析 Android 的 IPC 跨进程通信机制
  • C#11--14新特性
  • 力扣热题100道之最大子数之和
  • 手机网站开发c 教程一嗨租车网站建设的功能特色
  • 购物网站 app网站建设时应该做的优化
  • 深圳网站建设raygf2022年免费ppt模板下载
  • 【Python】二.判断语句
  • 【数据集】最新全国景区A-5A级景区数据集(更新至2025年)-含矢量及Excel详细
  • Linux线程 --- 线程控制、pthread线程库、线程栈、线程本地存储
  • C++:从0开始学习链表(练习)
  • JAVA的Set集合类
  • linux系统中进程控制
  • 网站域名注册证书是什么视频拍摄设备
  • 下载 LibreCAD 并创建个人分支的 Git 操作指南
  • 石家庄大型网站建站网站开发能从事那些职业
  • JavaScript性能优化实战大纲性能优化的核心目标
  • 【Android】布局优化:include、merge、ViewStub的使用及注意事项
  • PHP 桌面端框架NativePHP for Desktop v2 发布!
  • 第7章 muduo编程示例(2)
  • 哪里有放网站的免费空间无锡市政务服务网站建设项目
  • 为什么Unity修改过物体,物体的位移和旋转还是会被改变