uni-app에서 vue 구성 요소 부자값 전달
20214 단어 uni-app
<template>
<view>
<child :parentData="parentData"></child>
</view>
</template>
<script>
import child from "@/components/example/child.vue"
export default {
components: {
child: child
},
data() {
return {
parentData: ' ',
}
}
}
</script>
<style>
</style>
2.child
<template>
<view>
<text>{
{
parentData}}</text>
</view>
</template>
<script>
export default{
data(){
return{
}
},
props:{
parentData:{
type:String,
default:null
}
}
}
</script>
<style>
</style>
2. 서브어셈블리가 서브어셈블리에 데이터를 전달(emit)1.parent
<template>
<view>
<child :parentData="parentData" @changes="childClick" ></child>
<br>
<text>{
{
childData}}</text>
</view>
</template>
<script>
import child from "@/components/example/child.vue"
export default {
components: {
child: child
},
data() {
return {
parentData: ' ',
childData:''
}
},
methods:{
//
childClick(e) {
console.log(e)
this.childData = e;
}
}
}
</script>
<style>
</style>
2.child
<template>
<view>
<text>{
{
parentData}}</text>
<br>
<view style="width: 100%;">
<input class="uni-input" focus="true" type="text" value="search" v-model="search" placeholder=" " placeholder-class="color:#4a4a4a"/>
<button type="primary" @click="childClick"> </button>
</view>
</view>
</template>
<script>
export default{
data(){
return{
search:''
}
},
props:{
parentData:{
type:String,
default:null
}
},
methods:{
childClick(){
console.log(this.search);
this.$emit('changes',this.search)
}
}
}
</script>
<style>
</style>
3. 서브어셈블리와 부모어셈블리 데이터 동기화(.sync) 1.parent
<template>
<view>
<child :syncData.sync="syncData" ></child>
<view class="parent" style="background: #09BB07;">
<input :value="syncData" v-model="syncData" placeholder=" " style="background: #C0C0C0;" />
<view>sync (parent):{
{
syncData}}</view>
</view>
</view>
</template>
<script>
import child from "@/components/example/child.vue"
export default {
components: {
child: child
},
data() {
return {
syncData: ''
}
},
methods:{
}
}
</script>
<style>
</style>
2.child
<template>
<view>
<view>
sync (child):{
{
syncData}}
</view>
</view>
</template>
<script>
export default{
data(){
return{
}
},
props:{
syncData:{
type:String,
default:null
}
}
}
</script>
<style>
</style>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
uni-app 시스템 정보 얻기텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.