element-ui中table表头添加元素(或者图标)

element-ui中table表头添加元素(或者图标)_第1张图片
element-ui中table表头添加元素(或者图标)_第2张图片

实现功能:element-ui table表头开始单元格 添加元素。

直接上代码:

html


	//...这里面是其余的代码

js

mounted(){
	this.setLabel();
},

setLabel() {
	let _this = this;
	this.$nextTick(() => {
		let cellDiv = document.getElementsByClassName('cell use')[0]
		cellDiv.setAttribute("style","cursor:pointer");
		let node = document.createElement('i')
		node.setAttribute('class', 'el-icon el-icon-arrow-right')
		node.setAttribute('is-expand', 'no'); //设置属性is-expand的值
		node.onclick = function () {
			_this.cellDivClick.call(_this, node);
		}
		cellDiv.appendChild(node)
	})
},
cellDivClick(ele) {
	let state = ele.getAttribute('is-expand'); //获取属性is-expand的值
	//关闭的情况点击
	if (state === 'no') {
		//展开
		for(let i=0; i

总结 使用过directives 不好使,最后改成这种方式。虽然解决了,但是留有遗憾。因为指令不能成功实现。

你可能感兴趣的:(javascript)