Detailed explanation of Vue's props configuration

Detailed explanation of Vue's props configuration

insert image description here

<template>
  <div class="demo">
    <h1>{{ msg}}</h1>
    <h2>Student name: {{name}}</h2>
    <h2>Student gender: {{sex}}</h2>
    <h2>Student's age: {{myage+1}}</h2>
    <button @click="changeAge">Click me to modify data</button>
  </div>
</template>

<script>
  export default {
    name: 'Student',
    data() {
      return {
        msg: 'King's Lovers',
        myage:this.age
      }
    },
    methods: {
      changeAge(){
       this.myage=24
      }
    },
    //Simple reception// props:['name','age','sex']


    //Restrict the data type while receiving // props:{
    // name:String,
    //age:Number,
    // sex:String,
    // }

//While receiving data: limit the type + specify the default value + restrict the necessity props: {
      name: {
        type: String, //name type required: true, //name is required},
      age: {
        type: Number, 
       default:22
      },
      sex:
        type: String, 
        required: true
      }
 }

  }
</script>


<template>
  <div>
    <Student name="张三" sex="男" :myage="20"/>
  </div>
</template>

<script>
  //Import Student componentimport Student from './components/Student.vue'
  export default {
    name: 'App',
    components:
     Student
    }
  }

</script>

Summarize

This article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of how Vue handles various ways of writing props options
  • Vue props passes multiple value instances at a time
  • Detailed explanation of Vue's props configuration items
  • vue props type sets multiple types

<<:  Use tomcat to set shared lib to share the same jar

>>:  CSS code to distinguish ie8/ie9/ie10/ie11 chrome firefox

Recommend

WeChat applet to achieve the revolving lantern effect example

Preface In daily development, we often encounter ...

Html Select option How to make the default selection

Adding the attribute selected = "selected&quo...

A brief introduction to React

Table of contents 1. CDN introduction 1.1 react (...

A brief analysis of CSS3 using text-overflow to solve text layout problems

Basic syntax The use of text-overflow requires th...

Detailed explanation of XML syntax

1. Documentation Rules 1. Case sensitive. 2. The a...

General Guide to Linux/CentOS Server Security Configuration

Linux is an open system. Many ready-made programs...

js to achieve simple drag effect

This article shares the specific code of js to ac...

docker logs - view the implementation of docker container logs

You can view the container logs through the docke...

How to display JSON data in HTML

background: Sometimes we need to display json dat...

Detailed explanation of the implementation of shared modules in Angular projects

Table of contents 1. Shared CommonModule 2. Share...

Why not use UTF-8 encoding in MySQL?

MySQL UTF-8 encoding MySQL has supported UTF-8 si...

A brief talk about Mysql index and redis jump table

summary During the interview, when discussing abo...

Centos8 bridge static IP configuration method in VMware virtual machine

1. Make sure the network connection method is bri...