Vue makes judgments based on the input data

as shown in the figure, this is the weather navigation bar on the home page of Baidu. Now I use vue to do
. There is a demand for air pollution degree and numerical value. The air pollution value is the incoming data, such as 500,400. The air pollution degree is not the imported data, but is judged according to the incoming value. At which stage, the air pollution degree is displayed. For example, the air pollution index 500-600 is serious, the air pollution index 400-500 is severe, and the colors are different in different degrees

the code is as follows

template

<template>
    <div
        class="topnav_left_div">
        <span>
            {{ location }}
        </span>
        <img
            :src="weatherImgUrl">
        <span>
            {{ temperature }}
        </span>
        <span
            class="topnav_text">
            {{ airquality.degree }}
        </span>
        <span>
            {{ airquality.degreecount }}
        </span>
        <span>|</span>
    </div>
</template>

js

export default{
        data() {
            return {
                location: "",
                weatherImgUrl: require("@/assets/sun.png"),
                temperature: "20",
                airquality: {
                    degree: "",
                    degreecount: "500"
                }
            }
        }
    }

above is the previous code, which needs to be improved. How can I improve it?

Mar.04,2021

just write a computed:

{
    computed: {
        airqualityDegree(){
            if (this.degreecount < 100){
                return {
                  color: 'green',
                  text: ''  
                 }
            } else if (this.degreecount >= 100 && this.degreecount < 200){
                ... 
            }
        }
    }
}

consider binding to class or style with computational properties.
refer to the implementation of the link ide/class-and-style.html" rel=" nofollow noreferrer "> https://cn.vuejs.org/v2/guide.. If there is anything you don't understand, you can ask me, but it is highly recommended that you finish reading the class content of this chapter.


what you focus on is the judgment of polluting Chengdu. You can write a public method, pass in your natural data, and make all possible judgments in the method


bind the class class name, respectively.

Menu