Vue.js 设置:来自方法的样式
我对使用v-bind:style= 交易是样式属性的请求速度比我能提供的更快(挂载)。知道在我用宽度填充数组后如何强制更新吗Vue.js 设置:来自方法的样式,vue.js,vuejs2,vue-component,Vue.js,Vuejs2,Vue Component,我对使用v-bind:style= 交易是样式属性的请求速度比我能提供的更快(挂载)。知道在我用宽度填充数组后如何强制更新吗 {{header}} {{header}} 导出默认值{ 挂载:函数(){ 这是.getColumnWidths(); }, 方法:{ getHeight(索引){ 返回此项。标题宽度[索引]; }, getColumnWidths(){ 常数=这个; this.headers.forEach(函数(元素、索引){ _that.headerWidths[index]=\
{{header}}
{{header}}
导出默认值{
挂载:函数(){
这是.getColumnWidths();
},
方法:{
getHeight(索引){
返回此项。标题宽度[索引];
},
getColumnWidths(){
常数=这个;
this.headers.forEach(函数(元素、索引){
_that.headerWidths[index]=\u that.$refs['head'+index][0].clientWidth
});
},
},
数据:函数(){
返回{
标题:this.headersProp,
标题宽度:[],
}
}
}
如果有某种方法来强制更新,那就太好了,因为宽度可能会根据插入的内容而改变
不停摆弄
你被狗咬了。不要指定单个数组元素(使用
=
),而是使用:
你被狗咬了。不要指定单个数组元素(使用
=
),而是使用:
您的数组是否是一个可观察的Vue(例如视图模型的
数据
或计算的
属性)?其标题宽度为:[],位于数据
中。它开始是空的,在我渲染表之后,我想得到它的标题的宽度,这就是我使用getColumnWidths()所做的,你的数组是可以观察到的吗(例如,视图模型的data
或computed
属性)?它只是标题宽度:[],在data
中。它开始是空的,在我渲染表之后,我想得到它的标题的宽度,这就是我使用getColumnWidths()所做的,您可能会想使用\u that.$set(\u that.headerWidth,index,\u that.$refs['head'+index][0].clientWidth-32)
因为需要减去边框和填充的32个像素,所以您可能需要使用\u that.$set(\u that.headerwidth,index,\u that.$refs['head'+index][0].clientWidth-32)
因为需要减去边框和填充的32个像素
<template>
<div>
<div class="headings ">
<div class="t-cell head" v-for="(header, index) in headings"
:style="'min-width:'+ getHeight(index) +'px'"
>
{{header}}
</div>
</div>
</div>
<div class="fixed-table text-inline" >
<div class="t-cell head" v-for="(header, index) in headings" :ref="'head' + index">
{{header}}
</div>
</div>
</div>
</template>
<script>
export default {
mounted: function(){
this.getColumnWidths();
},
methods: {
getHeight(index){
return this.headerWidths[index];
},
getColumnWidths(){
const _that=this;
this.headings.forEach(function(element,index){
_that.headerWidths[index] = _that.$refs['head'+index][0].clientWidth
});
},
},
data: function () {
return {
headings: this.headersProp,
headerWidths:[],
}
}
}
</script>
getColumnWidths() {
const _that = this;
this.header.forEach(function(element, index) {
_that.$set(_that.headerWidths, index, _that.$refs['head' + index][0].clientWidth)
});
console.log(this.headerWidths);
},