2

Is it possible to just render once into an element?

Suppose I have a contenteditable div, and only want to render the first value, then stop rerendering as the model changes. Here only the initial value of variable will be rendered.

<div contenteditable="true"> {{variable}} </div>

2
  • as the modal changes ? the moment the first keyup happens ? Commented Apr 6, 2017 at 6:57
  • Just the initial value of the variable Commented Apr 6, 2017 at 9:09

1 Answer 1

7

Use v-once

<div contenteditable="true" v-once> {{variable}} </div>

You can also wrap it with a <span>:

<div contenteditable="true">
  <span v-once> {{variable}} </span>
</div>

refs:
https://v2.vuejs.org/v2/guide/components.html#Cheap-Static-Components-with-v-once https://v2.vuejs.org/v2/api/#v-once


Or another solution is simply clone the variable and just don't modify it, for example if you call it readOnlyVariable:

<div contenteditable="true"> {{readOnlyVariable}} </div>
Sign up to request clarification or add additional context in comments.

7 Comments

That is mainly for the components rendering, I can't put v-once on an element if it contains a lot of logic.. I just want to render the text once, not wrapped in an element.
What do you mean if it contains a lot of logic.? You can put v-once in a simple div; you can also wrap it with a component
So on the content-editable div I have a lot of v-on:, v-bind: etc. It is just the actual text node I want to render once, contained in the {{variable}}, not the contained element
Simply wrap it with a span <div contenteditable="true"><span v-once>{{variable}}</span></div>
Or just clone the variable to render, and don't modify the clone one
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.