The use of vue directive v-bind and points to note

The use of vue directive v-bind and points to note

1. v-bind: can bind some data to the attributes of the element

 <div id="app">

    <p v-bind:title="message" v-bind:id="pId">I am a p tag</p>

 </div>

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

          <script>

            let vm = new Vue({

                el:"#app",

                data:{

                    message: "I am the title value of the p tag",

                    pId: "This is a random ID"

                }

            })

The output is:

2. v-bind: can be abbreviated as: It is recommended to write the colon directly

<div id="app">

    <p :title="message" :id="pId">I am a p tag</p>

 </div>

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

          <script>

            let vm = new Vue({

                el:"#app",

                data:{

                    message: "I am the title value of the p tag",

                    pId: "This is a random ID"

                }

            })

The output is the same as above

3. v-bind: splicing of instruction expressions,

If you want to concatenate expressions, the concatenated strings must be wrapped in quotes, otherwise they will be parsed as variables.

Without quotes:

Error : [Vue warn]: Property or method "This is an additional id" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

Add quotes:

<p title="200" :title="message" :id="pId+'This is the additional id'">I am the p tag</p>

Output:

This is the end of this article about the use of v-bind and the points to pay attention to. For more information about the use and points to pay attention to of v-bind, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of V-bind directive in VueJs
  • Detailed explanation of the basic usage of v-bind in VUE
  • Vue.js study notes v-bind and v-on analysis
  • Vue uses v-bind to assign values ​​to src and href

<<:  CSS style does not work (the most complete solution summary in history)

>>:  Example of customizing the style of the form file selection box

Recommend

MySQL Oracle and SQL Server paging query example analysis

Recently, I have done a simple study on the data ...

Briefly understand the two common methods of creating files in Linux terminal

We all know that we can use the mkdir command to ...

Web interview Vue custom components and calling methods

Import: Due to project requirements, we will enca...

Sample code for batch deployment of Nginx with Ansible

1.1 Copy the nginx installation package and insta...

18 Web Usability Principles You Need to Know

You can have the best visual design skills in the...

CentOS 7 cannot access the Internet after modifying the network card

Ping www.baidu.com unknown domain name Modify the...

Detailed installation process of nodejs management tool nvm

nvm nvm is responsible for managing multiple vers...

CentOS 6 Compile and install ZLMediaKit analysis

Install ZLMediaKit on centos6 The author of ZLMed...

How to ensure the overall user experience

Related Articles: Website Design for User Experien...

InnoDB engine redo file maintenance method

If you want to adjust the size and number of Inno...

A brief discussion of several browser compatibility issues encountered

background Solving browser compatibility issues i...