The difference between Vue interpolation expression and v-text directive

The difference between Vue interpolation expression and v-text directive

{{message}} syntax can only be used in tag content

{{}} This syntax is called an interpolation expression. You can write any legal js expression in the interpolation expression.

1. Use plugin expressions

When using plugin expressions, there is a content flickering problem, but v-text does not have a flickering problem

<div id="app">

    <p>

        {{message}}

    </p>
   <p v-text="message"></p>

</div>

<script src="./js/vue.js"></script>
<script>

    let vm = new Vue({

        el:"#app",  

        data:{ 

        message:"hello vue"

    }

    })

</script>

In the above code, if the output is normal, the result is consistent.

However, if the network speed is slow, the plugin expression will be output on the page first.

{{message}}

The page will then be rendered normally, which is not good enough for the user experience.

2. Use v-cloak in plugin expressions to solve the flickering problem

<style>

    [v-cloak]:



    display:none;

}

</style>

<div id="app">

    <p v-cloak>

        {{message}}

    </p>

    <p v-text="message"></p>

</div>

<script src="./js/vue.js"></script>

We can use the v-cloak attribute to hide it at runtime, but vue will automatically delete v-cloak attribute at the end of the run.

So this method can be used to solve the flickering problem

3. Plugin Expression

Plugin expressions only insert content and do not overwrite the original content, while v-text will overwrite the original content.

<div id="app">

    <p>

        ----{{message}}----

    </p>

    //----hello vue----

    <p v-text="message">1234556</p>

    // hello vue

</div>

<script src="./js/vue.js"></script>
<script>

    let vm = new Vue({

        el:"#app",

         data:{
       message:"hello vue"
    }
    })

</script>

This is the end of this article about the difference between vue interpolation expressions and v-text directives. For more information about the difference between vue interpolation expressions and v-text directives, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How does Vue solve the problem of interpolation expression flickering when data is loaded?
  • A brief introduction to Vue interpolation expression Mustache
  • Summary of Vue interpolation, expression, separator, and instruction knowledge
  • Causes and solutions for flashing caused by v-if/v-show/interpolation expressions in Vue
  • Detailed explanation of interpolation expressions in Vue basic syntax

<<:  Solve the margin: top collapse problem in CCS

>>:  Use trigger method to realize pop-up file selection dialog box without clicking file type input

Recommend

How to configure the My.ini file when installing MySQL5.6.17 database

I recently used the MySql database when developin...

Solution to the ineffective global style of the mini program custom component

Table of contents Too long to read Component styl...

How to make form input and other text boxes read-only and non-editable in HTML

Sometimes, we want the text boxes in the form to b...

A Deep Dive into the MySQL InnoDB Storage Engine

Preface In MySQL, InnoDB belongs to the storage e...

Example of creating table statements for user Scott in MySQL version of Oracle

Overview: Oracle scott user has four tables, whic...

Detailed tutorial on using cmake to compile and install mysql under linux

1. Install cmake 1. Unzip the cmake compressed pa...

Detailed explanation of CSS sticky positioning position: sticky problem pit

Preface: position:sticky is a new attribute of CS...

Vue improves page response speed through lazy loading

Table of contents Overview What is lazy loading? ...

Detailed explanation of setting resource cache in nginx

I have always wanted to learn about caching. Afte...

How to display TIF format images in browser

The browser displays TIF format images Copy code T...

Why is your like statement not indexed?

Preface This article aims to explain the most bor...

Things about installing Homebrew on Mac

Recently, Xiao Ming just bought a new Mac and wan...

Two ways to remove the 30-second ad code from Youku video

I believe everyone has had this feeling: watching ...