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

Example of MySQL slow query

Introduction By enabling the slow query log, MySQ...

JavaScript design pattern chain of responsibility pattern

Table of contents Overview Code Implementation Pa...

What are the benefits of using // instead of http:// (adaptive https)

//Default protocol /The use of the default protoc...

The visual design path of the website should conform to user habits

Cooper talked about the user's visual path, w...

Complete steps to set up automatic updates in CentOS 8

The best thing you can do for your data and compu...

HTML Marquee character fragment scrolling

The following are its properties: direction Set th...

Why the table file size remains unchanged after deleting data in MySQL

For databases that have been running for a long t...

How to design and create adaptive web pages

With the popularization of 3G, more and more peop...

How to configure multiple tomcats with Nginx load balancing under Linux

The methods of installing nginx and multiple tomc...

Detailed steps and problem solving methods for installing MySQL 8.0.19 on Linux

I recently bought a Tencent Cloud server and buil...

WeChat applet implements the Record function

This article shares the specific code for the WeC...

DD DT DL tag usage examples

We usually use the <ul><li> tags, but ...

Javascript Virtual DOM Detailed Explanation

Table of contents What is virtual dom? Why do we ...