使用的是element框架,用vue的watch監(jiān)聽selectValue變化,當(dāng)變化時(shí)就觸發(fā)input[type=file]的click(),但是無效;html 相關(guān)代碼<el-select v-model="selectValue" placeholder="請(qǐng)選擇">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option></el-select><input type="file" ref="inputFile" id="inputFile">vue 相關(guān)代碼data () { return {
options:[{
value: '選項(xiàng)1',
label: '黃金糕'
}, {
value: '選項(xiàng)2',
label: '雙皮奶'
},],
selectValue:''
}
},
watch: {
selectValue: function(v) { // this.$refs.inputFile.click() 無效
// document.getElementById('inputFile').click() 無效
}
}