1. The parent component passes the value to the child component
1.1 Define the unknown to pass in the child component, define the name of the variable, and define the data type to pass:
Child components:
The code is as follows:
<template> <div class="navapp"> <div class="navbar"> <div class="navleft" @click="$router.go(-1)"> <img src=".. /assets/images/public/back.png" alt="" v-if="srcimg == true" /> <span>{{ navback }}</span> </div> <div class="navcenter">{{ navcenter }}</div> <div class="navright">{{ navright }}</div> </div> </div> </template> <script> export default { name: "NavBar", props: { srcimg: Boolean, navback:String, navcenter:String, navright:String }, }; </script>Copy the code
Improt (Improt, Improt, improt, ImproT, ImproT, ImproT, ImproT, ImproT, Improt, Improt
The parent component:
The code is as follows:
<template> <div class="home"> <NavBar :srcimg="true" :navback="back" navCenter ="back" navRight =" right "> </NavBar> </div> </template> <script> import NavBar from "@/components/NavBar.vue"; Export default {name: "Home", components: {NavBar,}, data() {return {back:' return '}; }}; </script>Copy the code