這里我想到了2個方法:
方法一:
直接給相應的元素加id,然后再document.getElementById("id");獲取,然后設置相應屬性或樣式
方法二:
使用ref,給相應的元素加ref=“name” 然后再this.$refs.name獲取到該元素
注意:在獲取相應元素之前,必須在mount鈎子進行掛載,否則獲取到的值為空,
如果是給子組件加id並修改自定義屬性,則直接會加載改子組件對應的外層div上,並不會改變該子組件原本的自定義屬性的值
如果給子組件加ref,然后獲取到該DOM元素之后改變相應的自定義屬性的值,vue會報錯:
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "title"