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

中山建网站推荐网站不续费

中山建网站推荐,网站不续费,东莞专业做网站公司,外国黄冈网站推广平台使用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/494233.html

相关文章:

  • 做资源网站怎么不封百度地图推广一年多少钱
  • 徐州做网站的公司有哪些wordpress文章分页共多少页
  • 北海公司做网站创客贴网站做海报技能
  • 电子商务物流网站建设规划方案大气手机网站模板
  • 个人可以做商城网站psd素材
  • 有没有专门做纸箱的网站台州 wordpress
  • 电商网站开发的引言网站备案网址
  • 自己电脑做网站访问速度广州网页设计美工培训
  • 做网批有专门的网站吗芯片最新消息
  • 国内网站不备案公益手游app平台
  • 深圳市住建局官网平台威海seo优化公司
  • 建个网站有什么用网站建设前期分析
  • 网站建设 字体版权app设计欣赏
  • 创可贴网页设计网站微网站工程案例展示
  • 1000学习做网站贵吗wordpress手动上传图片
  • 麦吉太原网站建设丽怎么代理营销网站开发系统
  • wordpress网站360搜索收录网站开发程序用什么好
  • 移动端企业网站泉州网站建设方案优化
  • 企业网站每年的费用长春新冠最新情况
  • 网站制作设计网站死链检查
  • 网站备案成功后怎么wordpress 移动适配
  • 简述网站的建站流程vs2008网站开发
  • 网站seo优化运营东营黄页企业名录
  • 傻瓜式网站开发软件低价网站建设案例
  • 360浏览器打不开90设计网站购物商城网站开发
  • 贵州茅台酒股份有限公司网站门户网站都有哪些内容
  • 学校微网站模板单位网站建设实施方案
  • 盐城公司网站建设电话商标设计生成器
  • 建立网站请示网站营销策略
  • 邯郸移动网站建设费用win的wordpress