我有一个全局变量,在安装组件时填充了 API 调用。 我还有一个图表组件,我想显示该变量是否为空(即请求已完成并已填充)。
目前我正在使用这个来渲染图表:
<template>
<div class="container">
<b-chart
v-if="$store.state.lists[api_key] != null"
:chartdata="$store.state.lists[api_key]"
:options="options"
/>
</div>
</template>
我已尝试将此检查 $store.state.lists[api_key] != null
移至 computed
或 watch
,以最小化内联脚本,但我似乎无法使其正常工作。有人能告诉我怎么做吗。
答案 0 :(得分:1)
试试这个:
computed: {
canShowChart() {
return this.$store.state.lists[this.api_key] != null;
}
}
<b-chart
v-if="canShowChart"
:chartdata="$store.state.lists[api_key]"
:options="options"
/>
答案 1 :(得分:1)
由于 url_html = urllib.request.urlopen(url)
soup = BeautifulSoup(url_html, "html.parser")
soup = str(soup)
emails = re.findall(r'[\w\.-]+@[\w\.-]+', soup)
值被解释为“falsy”,并且假设您有一个“api_key”数据变量,您可以这样使用它:
null
computed: {
chartData() {
return this.$store.state.lists[this.api_key]
}
}