父组件在调用子组件时,添加属性给子组件
<template>
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App" :newMsg="AppNewmsg"/>
</template>
<script>
import newWorld from './components/newWorld.vue'
export default {
name: 'App',
components: {
newWorld
},
data () {
return {
AppNewmsg: "111111111111111"
}
}
}
</script>
子组件中使用props接收
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<h1>新增传值:{{newMsg}}</h1>
</div>
</template>
<script>
export default {
name: 'newWorld',
props: {
msg: String,
newMsg: String
}
}
</script>
在子组件中会显示
Welcome to Your Vue.js App
新增传值:111111111111111