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

Table of CSS Bugs Caused by hasLayout

IE has had problems for a long time. When everyone...

How to solve the phantom read problem in MySQL

Table of contents Preface 1. What is phantom read...

A performance bug about MySQL partition tables

Table of contents 2. Stack analysis using pt-pmap...

Simple comparison of meta tags in html

The meta tag is used to define file information an...

Analysis of the use of Linux vulnerability scanning tool lynis

Preface: Lynis is a security audit and hardening ...

A brief discussion on docker compose writing rules

This article does not introduce anything related ...

Detailed examples of converting rows to columns and columns to rows in MySQL

mysql row to column, column to row The sentence i...

Pure CSS3 to achieve mouse over button animation Part 2

After the previous two chapters, do you have a ne...

Analysis of the principle and creation method of Mysql temporary table

This article mainly introduces the principle and ...

Detailed explanation of mkdir command in Linux learning

Table of contents Preface 1. Basic knowledge of f...