javascript - 在 vue js 的子组件中使用 getElementbyId 无法呈现自定义组件的样式
问题描述
我已将组件定义如下:
<template>
<div>
<span style="font-size: 16px">{{label}}</span>
<!-- <label style="font-size: 15px">{{ label }}</label> -->
<input
:class="{input:isSuccess, input_danger:isDanger, input_disabled:isDisabled}"
:style="{width:width}"
:id="id"
:type="type"
:max="max"
:min="min"
:state="state"
:placeholder="placeholder"
:disabled="disabled"
:value="value"
@input="handleInput"
@change="change"
/>
</div>
</template>
<script>
import TransformationVue from '../../pages/Transformation.vue';
export default {
props: {
value: [Number, String],
id: String,
label: String,
min: Number,
max: Number,
type: String,
state: Boolean,
placeholder: [Number, String],
isDanger:{
type:Boolean,
default:false
},
disabled:{
type:Boolean,
default:false
},
width:{
type:String,
default:'100%'
}
},
data() {
return {
minVal:this.min,
};
},
watch:{
disabled:function(){
alert('hello')
}
},
computed:{
isSuccess:function(){
if(this.isDanger == false && this.disabled == false ){
return true
}else {
return false
}
},
isDisabled:function(){
if(this.disabled ==true){
return true
}else{
return false
}
}
},
methods: {
handleInput(e) {
this.$emit("input", e.target.value);
},
change(e) {
if(this.type == 'number'){
if(e.target.value<this.min || e.target.value > this.max){
this.$emit("input", this.minVal)
this.$toast.error("Out of range!, Allowed range is "+this.min+" to" + this.max, { timeout: 6000 });
}else{
this.$emit("change")
}
}else{
this.$emit("change");
}
},
},
};
</script>
<style scoped>
.input {
font-size: 14px;
height: 40px;
border: 1px solid white;
border-radius: 4px;
border-bottom:4px solid #116b9d;
}
.input:hover {
border-bottom:4px solid #93d9ff;
background:rgb(255, 255, 255);
transition: none;
}
.input:focus {
border-bottom:4px solid #93d9ff;
background:rgb(255, 255, 255);
transition: none;
}
.input_danger {
font-size: 14px;
height: 40px;
border: 1px solid white;
border-radius: 4px;
border-bottom:4px solid rgb(255, 180, 180);
}
.input_disabled {
font-size: 14px;
height: 40px;
border: 1px solid white;
border-radius: 4px;
border-bottom:4px solid rgb(177, 177, 177);
}
.input_disabled:focus {
font-size: 14px;
height: 40px;
border: 1px solid white;
border-radius: 4px;
border-bottom:4px solid rgb(177, 177, 177);
}
</style>
在 vue 页面中,我使用了如下组件:
<template>
<aboveComponent
id='el'
@change="func"
:disabled="true"
/>
</template>
<script>
methods(){
func(){
document.getElementbyID('el').disabled = false
}
</script>
当我直接将 disabled 用作 true 或 false 时,组件样式正在更新,但是当我使用 document.getElementById 更改 disabled 属性时,禁用功能正在工作,但组件样式没有更新。
解决方案
推荐阅读
- c++ - 如何在单独的线程中创建多个任务?
- azure - Web App 上的 Azure 身份验证和对 Intranet Windows 身份验证 Web 服务的调用
- swift - Alamofire POST 应用程序/x-www-form-urlencoded 编码
- javascript - 背景滑块img上的下一个/上一个按钮
- highcharts - 如何在 Highcharts 上制作 3 种不同的颜色
- r - 将 Excel .xlsx 转换为 R 中的向量列表
- r - 是否可以在 R DT 包中保存编辑
- php - 比较PHP多维数组中的当前元素与前一个元素
- typescript - TypeScript 上的重载和回调
- ios - NSTimer retainCount 在失效后不为零