文本编辑器 Vue 组件
文本编辑器 Vue 组件表示文本编辑器组件。
文本编辑器组件
包含以下组件
f7-text-editor
文本编辑器属性
道具 | 类型 | 默认 | 描述 |
---|---|---|---|
<f7-text-editor> 属性 | |||
值 | 字符串 | 文本编辑器初始的 html 内容值。 | |
占位符 | 字符串 | 编辑器占位符内容在编辑器为空时显示。默认情况下未指定 | |
resizable | 布尔值 | false | 使编辑器可以调整大小(其高度将适应其内容) |
模式 | 字符串 | 工具栏 | 文本编辑器按钮模式。可以是
|
按钮 | 数组 | 带有编辑器按钮的数组,或带有编辑器按钮的数组(组)数组。默认情况下所有按钮都已启用,其默认值为
| |
分隔符 | 布尔值 | true | 在按钮组之间添加可视分隔符 |
图像 URL 文本 | 字符串 | 插入图像 URL | 在图像 URL 请求中显示的提示文本 |
链接 URL 文本 | 字符串 | 插入链接 URL | 在链接 URL 请求中显示的提示文本 |
粘贴时清除格式 | 布尔值 | true | 启用后,它将在从剪贴板粘贴时清除所有格式 |
自定义按钮 | 对象 | 包含自定义按钮的对象。对象属性键是按钮 id,应在 例如,要指定将添加
|
文本编辑器事件
事件 | 参数 | 描述 |
---|---|---|
<f7-text-editor> 事件 | ||
texteditor:change | (值) | 当编辑器值发生更改时将触发事件 |
texteditor:input | 将在编辑器内容的“input”事件中触发事件 | |
texteditor:focus | 将在编辑器内容获得焦点时触发事件 | |
texteditor:blur | 将在编辑器内容失去焦点时触发事件 | |
texteditor:buttonclick | (按钮 ID) | 将在单击编辑器按钮时触发事件 |
texteditor:keyboardopen | 当编辑器键盘工具栏出现时将触发事件 | |
texteditor:keyboardclose | 当编辑器键盘工具栏消失时将触发事件 | |
texteditor:popoveropen | 将在编辑器弹出窗口打开时触发事件 | |
texteditor:popoverclose | 将在编辑器弹出窗口关闭时触发事件 | |
texteditor:beforedestroy | 在 Text Editor 实例被销毁之前会触发事件 |
示例
text-editor.vue
<template>
<f7-page>
<f7-navbar title="Text Editor"></f7-navbar>
<f7-block>
<p>
Framework7 comes with a touch-friendly Rich Text Editor component. It is based on modern
"contenteditable" API so it should work everywhere as is.
</p>
<p>
It comes with the basic set of formatting features. But its functionality can be easily
extended and customized to fit any requirements.
</p>
</f7-block>
<f7-block-title>Default Setup</f7-block-title>
<f7-text-editor />
<f7-block-title>With Placeholder</f7-block-title>
<f7-text-editor placeholder="Enter text..." />
<f7-block-title>With Default Value</f7-block-title>
<f7-text-editor
placeholder="Enter text..."
:value="customValue"
@texteditor:change="(v) => (customValue = v)"
/>
<f7-block-title>Specific Buttons</f7-block-title>
<f7-block-header>It is possible to customize which buttons (commands) to show.</f7-block-header>
<f7-text-editor
placeholder="Enter text..."
:buttons="[
['bold', 'italic', 'underline', 'strikeThrough'],
['orderedList', 'unorderedList'],
]"
/>
<f7-block-title>Custom Button</f7-block-title>
<f7-block-header
>It is possible to create custom editor buttons. Here is the custom "hr" button that adds
horizontal rule:</f7-block-header
>
<f7-text-editor
placeholder="Enter text..."
:custom-buttons="customButtons"
:buttons="[['bold', 'italic', 'underline', 'strikeThrough'], 'hr']"
/>
<f7-block-title>Resizable</f7-block-title>
<f7-block-header>Editor will be resized based on its content.</f7-block-header>
<f7-text-editor
placeholder="Enter text..."
resizable
:buttons="['bold', 'italic', 'underline', 'strikeThrough']"
/>
<f7-block-title>Popover Mode</f7-block-title>
<f7-block-header
>In this mode, there is no toolbar with buttons, but they appear as popover when you select
any text in editor.</f7-block-header
>
<f7-text-editor
placeholder="Enter text..."
mode="popover"
:buttons="['bold', 'italic', 'underline', 'strikeThrough']"
style="--f7-text-editor-height: 150px"
/>
<f7-block-title>Keyboard Toolbar Mode</f7-block-title>
<f7-block-header
>In this mode, toolbar with buttons will appear on top of virtual keyboard when editor is in
the focus. It is supported only in iOS, Android cordova apps and in Android Chrome. When not
supported it will fallback to "popover" mode.</f7-block-header
>
<f7-text-editor
placeholder="Enter text..."
mode="keyboard-toolbar"
style="--f7-text-editor-height: 150px"
/>
<f7-block-title>As List Input</f7-block-title>
<f7-block-header
>Text editor can be used in list with other inputs. In this example it is enabled with
"keyboard-toolbar"/"popover" type for "About" field.</f7-block-header
>
<f7-list strong-ios dividers-ios outline-ios>
<f7-list-input type="text" label="Name" placeholder="Your name" />
<f7-list-input
type="texteditor"
label="About"
placeholder="About"
resizable
:text-editor-params="{
mode: 'popover',
buttons: ['bold', 'italic', 'underline', 'strikeThrough'],
}"
:value="listEditorValue"
@texteditor:change="(value) => (listEditorValue = value)"
/>
</f7-list>
</f7-page>
</template>
<script>
import {
f7Page,
f7Navbar,
f7BlockTitle,
f7BlockHeader,
f7Block,
f7TextEditor,
f7List,
f7ListInput,
} from 'framework7-vue';
export default {
components: {
f7Page,
f7Navbar,
f7BlockTitle,
f7BlockHeader,
f7Block,
f7TextEditor,
f7List,
f7ListInput,
},
data() {
return {
customButtons: {
hr: {
content: '<hr>',
onClick() {
document.execCommand('insertHorizontalRule', false);
},
},
},
customValue: `<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Consequatur sunt, sapiente quis eligendi consectetur hic asperiores assumenda quidem dolore quasi iusto tenetur commodi qui ullam sint sed alias! Consequatur, dolor!</p>
<p>Provident reiciendis exercitationem reprehenderit amet repellat laborum, sequi id quam quis quo quos facere veniam ad libero dolorum animi. Nobis, illum culpa explicabo dolorem vitae ut dolor at reprehenderit magnam?</p>
<p>Qui, animi. Dolores dicta, nobis aut expedita enim eum assumenda modi, blanditiis voluptatibus excepturi non pariatur. Facilis fugit facere sequi molestias nemo in, suscipit inventore consequuntur, repellat perferendis, voluptas odit.</p>
<p>Tempora voluptates, doloribus architecto eligendi numquam facilis perspiciatis autem quam voluptas maxime ratione harum laudantium cum deleniti. In, alias deserunt voluptatibus eligendi libero nobis est unde et perspiciatis cumque voluptatum.</p>
<p>Quam error doloribus qui laboriosam eligendi. Aspernatur quam pariatur perspiciatis reprehenderit atque dicta culpa, aut rem? Assumenda, quibusdam? Reprehenderit necessitatibus facere nemo iure maiores porro voluptates accusamus quibusdam. Nesciunt, assumenda?</p>`,
listEditorValue: '',
};
},
};
</script>