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

Linux kernel device driver kernel linked list usage notes

/******************** * Application of linked lis...

Usage of MySQL time difference functions TIMESTAMPDIFF and DATEDIFF

Usage of time difference functions TIMESTAMPDIFF ...

Start nginxssl configuration based on docker

Prerequisites A cloud server (centOS of Alibaba C...

HTML set as homepage and add to favorites_Powernode Java Academy

How to implement the "Set as homepage" ...

How to add links to FLASH in HTML and make it compatible with all major browsers

Look at the code first Copy code The code is as fo...

MySQL 5.7.18 Green Edition Download and Installation Tutorial

This article records the detailed process of down...

How to Dockerize a Python Django Application

Docker is an open source project that provides an...

Eight rules for effective web forms

If you're collecting information from your us...

A complete guide on how to query and delete duplicate records in MySQL

Preface This article mainly introduces the method...

Several things to note when making a web page

--Homepage backup 1.txt text 2. Scan the image 3. ...

SQL statements in Mysql do not use indexes

MySQL query not using index aggregation As we all...

Tutorial on installing phpMyAdmin under Linux centos7

yum install httpd php mariadb-server –y Record so...

Implementation principle and configuration of MySql master-slave replication

Database read-write separation is an essential an...