我用最笨的方法,先实现功能先,用两个input,一个可以编辑,一个不可以编辑,失去焦点后隐藏可以点击的那个,点“编辑”时,显示可以编辑的那个input

          <div class="edit-item">
<input type="text" id="group-name" v-model="groupName" class="edit-input" disabled v-show="!isEditGroupName" >
<input type="text" id="group-name2" v-model="groupName" class="edit-input" ref="groupName"
@input="changeValue"
@change="editGroupNameSave(groupInfo.name)" v-show="isEditGroupName" @blur="isEditGroupName = false">
<span @click="editGroupName"><icon-svg name="icon-kaka-compile" icon-style="edit-ico"></icon-svg></span>
</div>

export default {
name: 'RightSideBar',
props: {
},
data () {
return {
isEditGroupName: false, // 修改群名称
}
},
computed: {
// 群名称
groupName: {
get () {
return this.$store.getters.groupSetInfo.name
},
set (val) {
// 使用vuex中的mutations中定义好的方法来改变
let groupSetInfo = this.$store.getters.groupSetInfo
let copyMyinfo = Object.assign({}, groupSetInfo)
copyMyinfo.name = val
this.$store.dispatch('groupSetInfo', copyMyinfo)
}
},
},
methods: {
changeValue () {
let leng = this.validateTextLength(this.groupName)
if (leng >= 15) {
this.$refs.groupName.maxLength = leng
} else {
this.$refs.groupName.maxLength = 30
}
},
validateTextLength (value) {
// 中文、中文标点、全角字符按1长度,英文、英文符号、数字按0.5长度计算
let cnReg = /([\u4e00-\u9fa5]|[\u3000-\u303F]|[\uFF00-\uFF60])/g
let mat = value.match(cnReg)
let length
if (mat) {
length = (mat.length + (value.length - mat.length) * 0.5)
return length
} else {
return value.length * 0.5
}
},
// 打开编辑
editGroupName () {
this.isEditGroupName = true
let nickNameInput = document.querySelector('#group-name2')
setTimeout(() => {
nickNameInput.focus()
}, 0)
},
// 保存群名修改
editGroupNameSave (data) { }, },
created () {
}

编辑

vue 设置 input 为不可以编辑的更多相关文章

  1. vue设置input不可编辑切换

    html: <Input name="a" v-model="formValidate.coName" placeholder="请输入姓名&q ...

  2. [oldboy-django][2深入django]学生管理(Form)-- 编辑(设置input标签属性,设置input标签默认显示值,设置input的类型)

    1 django 后台实现设置input标签属性,设置input标签默认显示值,设置input输入框类型 # Form生成html标签 a. 通过Form生成Input输入框,Form标签,以及sub ...

  3. 设置input框文字垂直居中和宽度

    input { solid #999;height:22px; background:#ffffff; line-height:22px; margin:0px; padding:0px;/*表单输入 ...

  4. 使input文本框不可编辑的3种方法

    一:disabled disabled 属性规定应该禁用 input 元素,被禁用的 input 元素,不可编辑,不可复制,不可选择,不能接收焦点,后台也不会接收到传值.设置后文字的颜色会变成灰色.d ...

  5. css设置input中placeholder字体

    设置input中placeholder字体颜色 input::-webkit-input-placeholder {color:@a;} input:-moz-placeholder {color:@ ...

  6. 设置DataGridView 显示自己添加编辑的列名,不动态显示数据库本身

    设置DataGridView 显示自己添加编辑的列名,不动态显示数据库本身. 方法: (1)界面操作,把DataGridView控件拖放在窗体中,就看到DataGridView控件的右上角有个小三角, ...

  7. JQuery设置input属性(disabled、enabled)

    document.getElementById("removeButton").disabled = false; //普通Js写法 $("#removeButton&q ...

  8. Vue 限制input输入 限数字 或 小数点后两位number

    Vue 限制input输入 小数点后两位number <input type="number" @keydown="handleInput2" place ...

  9. 设置input标签的placeholder的样式

    设置input样式代码: input::-webkit-input-placeholder{ /*WebKit browsers*/ color: red; } input::-moz-input-p ...

随机推荐

  1. char* a = "abc" 和 char a[] = "abc" 之间的区别

    char* a = "abc"; 声明了一个字符类型的指针a,并为它赋值初始值为"abc",a的值是字符串"abc"的首地址[第一个字符的地 ...

  2. linux等 入门思维导图

  3. Fuzzy logic

    Fuzzy logic is used in artificial intelligence. In fuzzy logic, a proposition has a truth value that ...

  4. 从MAP角度理解神经网络训练过程中的正则化

    在前面的文章中,已经介绍了从有约束条件下的凸优化角度思考神经网络训练过程中的L2正则化,本次我们从最大后验概率点估计(MAP,maximum a posteriori point estimate)的 ...

  5. python 并发编程 协程 gevent模块

    一 gevent模块 gevent应用场景: 单线程下,多个任务,io密集型程序 安装 pip3 install gevent Gevent 是一个第三方库,可以轻松通过gevent实现并发同步或异步 ...

  6. vs资源视图加载失败

    原因:引用了未知的资源,通过打开时报的错可以定位然后修改

  7. 【Linux 网络编程】OSI七层模型

    OSI(Open System Interconnection)开放系统互联模型(1)应用层: 应用层与应用程序界面沟通,以达到展示给用户的目的.(2)表示层: 表示层对网络传输的数据进行交换,使得多 ...

  8. [转帖]Chrome 错误代码:ERR_UNSAFE_PORT

    Chrome 错误代码:ERR_UNSAFE_PORT 2018年07月18日 09:07:50 孤舟听雨 阅读数 182 https://blog.csdn.net/u013043762/artic ...

  9. Labeling Balls POJ - 3687 优先队列 + 反向拓扑

    优先队列 + 反向拓扑 //#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include ...

  10. 【二】Django 视图和url配置

    在新建的Django项目下,新建一个views的python文件,编辑如下代码 from django.http import HttpResponse def hello(request): ret ...