VueJS 渲染一次到一个元素 [英] VueJS render once into an element

查看:30
本文介绍了VueJS 渲染一次到一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以只渲染一次到一个元素中?

假设我有一个 contenteditable div,并且只想渲染第一个值,然后在模型更改时停止重新渲染.这里只会渲染variable的初始值.

{{variable}} </div>

解决方案

使用 v-once

{{变量}} </div>

你也可以用 包裹它:

<span v-once>{{变量}} </span>

参考:
https://vuejs.org/v2/guide/components.html#Cheap-Static-Components-with-v-oncehttps://vuejs.org/v2/api/#v-once><小时>

或者另一种解决方案是简单地克隆 variable 并且不要修改它,例如,如果您将其称为 readOnlyVariable:

{{readOnlyVariable}} </div>

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>

解决方案

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://vuejs.org/v2/guide/components.html#Cheap-Static-Components-with-v-once https://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>

这篇关于VueJS 渲染一次到一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆