VueJS conditionally add an attribute for an element

前端 未结 7 1553
旧时难觅i
旧时难觅i 2020-12-02 09:15

In VueJS we can add or remove a DOM element using v-if:


but is there a wa

7条回答
  •  广开言路
    2020-12-02 09:25

    It's notable to understand that if you'd like to conditionally add attributes you can also add a dynamic declaration:

    
    

    where attrs is declared as an object:

    data() {
        return {
            attrs: {
                required: true,
                type: "text"
            }
        }
    }
    

    Which will result in:

    
    

    Ideal in cases with multiple attributes.

提交回复
热议问题