我正在尝试使用openweathermap的计算属性来更改一个简单天气应用程序的字体超赞图标,使用条件来更改图标。无论我做什么,我都不知道它为什么要使用else返回。
<template>
<h2>{{ city }}</h2>
<p>{{ temp }} F°</p>
<p>{{ conditions }}</p>
<font-awesome-icon class="icon-weather" :icon="weatherIcon" />
</template>
<script>
export default {
props: ["city", "temp", "conditions"],
computed: {
weatherIcon() {
let conditions = this.conditions;
if (conditions === "snow") {
return "snowflake";
} else if (conditions === "light snow") {
return "snowflake";
} else {
return "cloud";
}
},
},
};
</script>
<style scoped>
.icon-weather {
font-size: 50px;
}
</style>发布于 2021-02-01 00:40:06
我认为这是因为Vue没有重新渲染font-awesome-icon组件。
尝试使用属性key和值weatherIcon将新的绑定属性附加到font-awesome-icon。这个技巧将使一个力重新渲染该组件。
<font-awesome-icon
:key="weatherIcon"
class="icon-weather"
:icon="weatherIcon"
/>https://stackoverflow.com/questions/65981260
复制相似问题