- <div>
- son组件
- <div>父组件的值{{ text }}div>
- div>
-
- <script>
- export default {
- props: ["text"],
- data() {
- return {};
- },
- methods: {},
- components: {},
- };
- script>
-
- <style scoped lang="less">
- style>
- <div class="about">
- <h1>This is an about pageh1>
- 父组件
- <son :text="age">son>
- div>
-
- <script>
- import son from "@/components/son.vue";
- export default {
- props: {},
- data() {
- return {
- age: 200,
- };
- },
- methods: {},
- components: {
- son,
- },
- };
- script>
-
- <style scoped lang="less">
- style>
give(){
this.$emit('getIt', this.sonLists)
}
//sonLists表示子组件要传给父组件的值
后面代表父组件的事件名
getVal(v){
this.sonVal=v
console.log(v);
}
//sonVal在父组件中定义,来接收子组件传过来的值