Smart.Editor Auto Load/Save

Editor for Vue

Vue 3 version using Smart custom elements and template refs.

What this topic covers: practical setup, the framework-specific API access pattern, and copy-adapt guidance for the examples in this page.

<script setup>
import { onMounted, ref } from 'vue';
import 'smart-webcomponents/source/styles/smart.default.css';
import 'smart-webcomponents/source/modules/smart.editor.js';

const component = ref();
const componentProps = {
  // Copy this topic's JavaScript configuration here.
};

onMounted(() => {
  Object.assign(component.value, componentProps);
});
</script>

<template>
  <smart-editor ref="component"></smart-editor>
</template>

Use component.value for API methods in this topic.

Editor Content State Handling

Smart.Editor's allows to automatically store the content to local storage. The autoSaveInterval property determines the interval between each save. The property accepts numeric values as miliseconds. The default interval value is set to 1000ms (1 second). The content is saved only while the Editor is focused.

The auto save feature is not enabled by default. The autoSave property enables/disabled the feature.

The auto load feature of the Editor allows the user to continue from where he left off after re-opening the page. The autoLoad property determines whether the Editor will automatically load the last saved state.

In order for both property to work the Editor should have an id set.

Methods

Additional methods are available for manually saving or loading the Editor:

  • saveState - saves the current state of the Editor to local storage.
  • loadState - this method takes one optional argument which represents a previously saved content of the Editor. If not provided, a local storage lookup for a previously saved state of the Editor will be performed.
  • clearState - clears any stored state of the Editor from Local storage. (Depending on the id of the Editor)
const editor = component.value;

component.value.saveState();
component.value.loadState();
component.value.clearState();
For AI tooling

Developer Quick Reference

Topic: editor-auto-save   Component: Editor   Framework: Vue

Main methods: saveState(), loadState(), clearState()

Common config keys: (none detected)

Implementation Notes

Compatibility: Vue 3+   API access pattern: const component = ref() + component.value.method()

Lifecycle guidance: Use template refs with