uni-app
uni-app copied to clipboard
uni.createInnerAudioContext 通过 watch 监听 src ,在微信小程序中不会触发
问题描述
在 globalData 中通过 uni.createInnerAudioContext 创建音频播放器设置 src 地址,并且在组件通过 watch 监听,在 h5 可以触发 watch 事件,但是在微信小程序环境下不会触发 watch 事件。
复现步骤
- 在 globalData 中配置
// App.vue
globalData:{
audio: uni.createInnerAudioContext(),
}
- 在组件中监听
<template>
<view>
<view>{{player.src}}</view>
<button @click="handler">修改地址</button>
</view>
</template>
<script>
export default {
data(){
return{
player:getApp().globalData.audio
}
},
watch:{
'player.src'(n){
console.log(n,'修改')
}
},
methods:{
handler(){
this.player.src= 'https://bjetxgzv.cdn.bspapp.com/VKCEYUGU-hello-uniapp/2cc220e0-c27a-11ea-9dfb-6da8e309e0d8.mp3'
}
}
}
</script>
-
h5 运行结果

-
微信小程序运行结果

没有任何输出但是实际上已经去获取音频文件了。
预期结果 如果可以希望小程序环境能够和 h5 保持一致,均可触发 watch
系统信息: uni-app版本:
{
name: 'uni',
versions: [
'0.0.0',
'0.0.1',
'0.0.2',
'0.0.3',
'0.0.4',
'0.0.5',
'0.0.6'
],
time: {
created: '2022-01-27T17:41:46.653Z',
modified: '2022-01-27T17:41:46.653Z',
'0.0.0': '2014-05-09T14:06:03.091Z',
'0.0.1': '2014-05-09T21:35:07.653Z',
'0.0.2': '2014-05-12T10:58:17.678Z',
'0.0.3': '2014-05-12T20:49:47.584Z',
'0.0.4': '2014-05-13T12:28:24.861Z',
'0.0.5': '2014-05-16T08:06:28.772Z',
'0.0.6': '2014-06-02T15:12:57.118Z'
},
users: {},
'dist-tags': {
latest: '0.0.6'
},
version: '0.0.6',
description: 'uni',
main: 'index.js',
scripts: {
test: 'echo "Error: no test specified" && exit 1'
},
repository: {
type: 'git',
url: 'github.com/3rd-Eden/uni'
},
keywords: [
'clone',
'flow',
'generator',
'git',
'npm',
'orchestrate',
'plan',
'scaffolding',
'uni',
'workflow'
],
author: {
name: 'Arnout Kazemier'
},
license: 'MIT',
bugs: {
url: 'https://github.com/3rd-Eden/uni/issues'
},
homepage: 'https://github.com/3rd-Eden/uni',
dependencies: {
argh: '0.1.x',
debug: '0.8.x',
'dot-component': '0.1.x',
eventemitter3: '0.1.x',
fusing: '0.2.x',
githulk: '0.1.x',
natural: '0.1.x',
'npm-registry': '0.1.x',
pathval: '^0.1.1',
semver: '2.3.x',
shelljs: '0.3.x'
},
bin: {
uni: './bin/uni'
},
maintainers: [
{
name: 'V1',
email: '[email protected]'
}
],
dist: {
shasum: 'b763574becc895e69eb84bec9c72533fa123812e',
tarball: 'http://192.168.200.225/uni/-/uni-0.0.6.tgz',
size: 14395,
integrity: 'sha512-X/lCwU0q7Bubv9FJFs6EDTL/CF5n4URrpPs07QOkFbFtGAkSXk6mpMYF0qfQ6xfwhvyvWuYfSA3mnQC/pEOtDQ=='
},
directories: {},
contributors: []
}