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

Design Reference Beautiful and Original Blog Design

All blogs listed below are original and uniquely ...

Nginx reverse proxy configuration removes prefix

When using nginx as a reverse proxy, you can simp...

How to build sonarqube using docker

Table of contents 1. Install Docker 2. Install so...

Summary of Linux commands commonly used in work

Use more open source tools such as docker and kub...

Details after setting the iframe's src to about:blank

After setting the iframe's src to 'about:b...

Discussion on default margin and padding values ​​of common elements

Today we discussed the issue of what the margin v...

Detailed explanation of the use of find_in_set() function in MySQL

First, let’s take an example: There is a type fie...

CSS Naming: BEM, scoped CSS, CSS modules and CSS-in-JS explained

The scope of css is global. As the project gets b...

Solution to the long delay of MySQL database master-slave replication

Preface The delay of MySQL master-slave replicati...

Steps to use autoconf to generate Makefile and compile the project

Preface Under Linux, compilation and linking requ...

MySQL cross-table query and cross-table update

Friends who have some basic knowledge of SQL must...

HTML web page image tag

Insert image tag <IMG> The colorful web page...

Difference between MySQL btree index and hash index

In MySQL, most indexes (such as PRIMARY KEY, UNIQ...