Install @wysimark/vue using
npm i --save @wysimark/vue
or
yarn add @wysimark/vue
or
pnpm add @wysimark/vue
You can import the Wysimark component from @wysimark/vue
and use it in your Vue template.
Here's an example followed by an explanation of what's going on.
<template>
<wysimark v-model="markdown" :height="320" />
</template>
<script>
import Wysimark from "@wysimark/vue";
export default {
name: "App",
components: { Wysimark },
setup() {
const markdown = ref<string>("# Hello World\n\nLorem ipsum dolar...");
return {
markdown,
};
},
};
</script>
In the script portion of the .vue
file...
First, import and expose the Wysimark
component
Next, create a reactive reference with the ref
method and return it from the setup
method. This makes it available in the <template>
Finally, set the v-model
attribute on the <wysimark>
component to the reactive reference.
To support file attachment uploads, image uploads and server-side image resizing:
auth-token
to the Wysimark component.<template>
<wysimark v-model="markdown" :height="320" auth-token="AUTH_TOKEN_GOES_HERE"/>
</template>
<script>
import Wysimark from "@wysimark/vue";
export default {
name: "App",
components: { Wysimark },
setup() {
const markdown = ref<string>("# Hello World\n\nLorem ipsum dolar...");
return {
markdown,
};
},
};
</script>
The Wysimark component is used to render the Wysimark editor.
You can use it like this:
<template>
<wysimark v-model="markdown" :height="320" />
</template>
<script>
import Wysimark from "@wysimark/vue";
export default {
name: "App",
components: { Wysimark },
setup() {
const markdown = ref<string>("# Hello World\n\nLorem ipsum dolar...");
return {
markdown,
};
},
};
</script>
The Wysimark Component has these props:
const props = {
modelValue: { type: String, required: true }, // model-value
authToken: { type: String, required: false }, // auth-token
height: { type: Number, required: false }, // height
minHeight: { type: Number, required: false }, // min-height
maxHeight: { type: Number, required: false }, // max-height
onChange: { type: Function, required: false }, // on-change
throttleInMs: { type: Number, required: false }, // throttle-in-ms
placeholder: { type: String, required: false }, // placeholder
}
model-value
String
true
Example:
To use the model-value
prop, you can bind a data property to it like this:
<wysimark model-value="# Hello World" />
You can also use it with v-model
like this:
<wysimark v-model="markdown" />
Where markdown
is a reactive reference.
auth-token
String
false
height
Number
false
min-height
and max-height
separately using the respective props.min-height
Number
false
max-height
Number
false
on-change
Function
false
markdown
(String) - The markdown contentmodel-value
(i.e. the Markdown content) changes. Note that this function will be called by default once every 1000ms. You can change this interval by setting the throttle-in-ms
prop.throttle-in-ms
Number
false
on-change
function is called. The default value is 1000
(i.e. 1 second).placeholder
String
false
The Wysimark component exposes the update:model-value
event.
update:model-value
String
@update:model-value
event is emitted by the component when there is a need to update the value of its modelValue
prop. This event supports two-way binding using v-model
. Note that this event is emitted by default once every 1000ms. You can change this interval by setting the throttle-in-ms
prop.getMarkdown() => String
This method returns the current Markdown in the editor.
NOTE: If there are any images or files that are not finished uploading, they will not be returned as part of the Markdown.
setMarkdown(markdown: string) => void
This method allows you to set the Markdown in the editor. It will overwrite any existing Markdown in the editor.