【发布时间】:2020-05-21 19:03:09
【问题描述】:
我在export default 对象之外有一个函数。如何让停止按钮在 1 秒后变为播放按钮?
简而言之:我想将playingStatus 更改为超出范围的false。
请查看{N} PlayGround link for question
<template>
<Page>
<ActionBar title="Home" />
<ScrollView>
<StackLayout>
<Image v-show="!playingStatus" @tap="startFunc"
src="https://cdn3.iconfinder.com/data/icons/iconic-1/32/play_alt-512.png"
stretch="aspectFit" />
<Image v-show="playingStatus"
src="https://cdn3.iconfinder.com/data/icons/eightyshades/512/24_Stop-512.png"
stretch="aspectFit" />
</StackLayout>
</ScrollView>
</Page>
</template>
<script>
function playForAWhile() {
setTimeout(stop, 1000);
}
function stop() {
playingStatus =
false; // scope error... How to change vue data from outside?
}
export default {
data() {
return {
playingStatus: false
};
},
methods: {
startFunc() {
this.playingStatus = true;
playForAWhile();
}
}
};
</script>
<style scoped>
</style>
或者,我如何在没有 vue 对象的情况下切换图像,而不是从外部更改变量。 提前致谢。
【问题讨论】:
-
配合这个组件的一个方法的函数。这样你就可以操纵它的数据;)
-
你的意思是'''stop'''函数吗?
-
是的,为什么您需要在组件之外使用它?你想达到什么目标?
-
现在 Stop 没有定义。 play.nativescript.org/?template=play-vue&id=SLVQeY&v=9我认为vue对象和脚本部分之间一定有一种桥梁。
-
Method.call(this: vue, ...arcs)
标签: vue.js vuejs2 nativescript-vue