一.父组件关键代码:
<template> <div id="app"> <h1>title</h1>
<Survey-form ref = "SurveyForm" ></Survey-form> <!--说明: 注册 ref 子主键 -->
</template>
<script>
import axios from 'axios'
import SurveyForm from './components/SurveyForm'
import SelectForm from './components/SelectForm'
export default {
name: 'App',
components: {
SurveyForm,SelectForm
},
methods:{
selecty:function(v){
//在父主键方法内,执行子组件方法:callApi
vm.$refs.SurveyForm.callApi()
}
</script>
二.子组件
略... <script> methods:{ callApi:function () { ...略... } } </script>