向父组件传参
父组件创建回调函数,子组件特殊方法调用
// 向父组件传参
UniViewJSBridge.publishHandler('onWxsInvokeCallMethod', {
cid: this._$id,
method: 'renderjsCall',
args: {
type: '1',
name: '2'
}
})
向子组件传参
使用 prop 传递数据,子组件监听数据变化
<view id="echarts" :prop="control" :change:prop="echarts.update"></view>
示例
<template>
<view class="content">
<!-- #ifdef APP-PLUS || H5 -->
<view :prop="option" :change:prop="echarts.updateEcharts" id="echarts" class="echarts"></view>
<!-- #endif -->
<!-- #ifndef APP-PLUS || H5 -->
<view>非 APP、H5 环境不支持</view>
<!-- #endif -->
</view>
</template>
<script>
export default {
data() {
return {
option: {
title: {
text: 'ECharts'
},
},
}
},
}
</script>
<script module="echarts" lang="renderjs">
export default {
mounted() {
this.initEcharts()
},
methods: {
initEcharts() {
// 观测更新的数据在 view 层可以直接访问到
console.log(11111,this.option);
},
updateEcharts(newValue, oldValue, ownerInstance, instance) {
// 监听 service 层数据变更
console.log(22222,this.option);
},
}
}
</script>