网上查过很多相关文章都没有一章是写element ui滑块带范围实现双向绑定 二个滑块二头的数据怎么得到 我的需求是做个时间轴要滑动选择不同的时间 开始很难做最后一点一点摸索得出的结论 好在写出来了先给大家看实体图

就是这样的 给大家贴代码 多余的代码我就不贴了 就给你们看主要的

 <div>
<el-dialog
title="聊天记录"
:visible.sync="showFlag"
width="850px"
@close="closeDialog"
center
>
<div>
<div class="block">
<el-slider
v-model="value"
range
:marks="marks"
:max="300"
:step="1"
@change="schedule()"
style="margin-bottom:10px;"
:format-tooltip="formatTooltip"
>
</el-slider>
</div>
</div>
</el-dialog>
</div>
<el-button size="mini" @click="showChart(scope)">查看聊天记录</el-button>

再是函数方法里面的

这是点击按钮进入聊天弹框触发的函数
showChart(scope) {
this.value = [120, 140]
this.liveIdRow = scope.row.LiveID
this.TeacherIDRow = scope.row.TeacherID
this.searchValue.time = []
this.data = []
if (scope) {
var startTime = scope.row.StartTime
var endTime = moment(startTime)
.add(20, 'm')
.format('YYYY-MM-DD HH:mm:ss')
this.searchValue.time.push(startTime)
this.searchValue.time.push(endTime)
this.focusTimeList = []
for (var i = 0; i < 7; i++) {
this.focusTimeList.push(
moment(startTime)
.add(60 * i, 'm')
.format('YYYY-MM-DD HH:mm:ss')
)
}
this.focusTimeListTwo = []
for (var k = 0; k < 3; k++) {
this.focusTimeListTwo.push(
moment(this.focusTimeList[0])
.add(-60 * k, 'm')
.format('YYYY-MM-DD HH:mm:ss')
)
}
}
this.loading = true
this.showFlag = true
this.recordList = []
var body = {
liveid: this.liveIdRow,
teacherid: this.TeacherIDRow,
start: this.searchValue.time[0],
end: this.searchValue.time[1]
}
return request({
method: 'get',
url: '/api/teacher/chat',
params: body
}).then(res => {
if (res.Content) {
this.messages = res.Content
this.messages.forEach(item => {
var num = parseInt(19 * Math.random())
item.img = require(`../../../assets/auter/icon-test_${num}.png`)
item.msgs = item.msg
.replace(/\[e\]em_/g, '<img src=../../../static/faces/em_')
.replace(/\[e\]/g, '.png>')
})
this.recordList = this.messages
this.loading = false
} else {
this.$message({
message: '无分析结果!',
type: 'warning'
})
this.loading = false
}
})
},
这是滑块自带的函数你可以去elementui官网看一下了解一下大概就是你滑动一下滑块每次都触发的函数
formatTooltip(val) {
this.val = val
this.marks = {
0: this.focusTimeListTwo[2].substring(11, 19),
60: this.focusTimeListTwo[1].substring(11, 19),
120: this.focusTimeList[0].substring(11, 19),
180: this.focusTimeList[1].substring(11, 19),
240: this.focusTimeList[2].substring(11, 19),
300: this.focusTimeList[3].substring(11, 19)
}
if (val != null) {
var hour = this.focusTimeListTwo[2].substring(11, 13)
var min = this.focusTimeListTwo[2].substring(14, 16)
if (val < 60 || val == 60) {
min = min * 1 + val
if (min == 60) {
min = 0
hour = this.focusTimeListTwo[1].substring(11, 13) * 1
}
hour = hour * 1
if (min > 60) {
min = min - 60
hour = hour + 1
}
}
if ((val > 60 && val < 120) || val == 120) {
min = this.focusTimeListTwo[1].substring(14, 16) * 1
hour = this.focusTimeListTwo[1].substring(11, 13) * 1
min = min * 1 + val - 60
if (min == 60) {
min = 0
hour = this.focusTimeList[0].substring(11, 13) * 1
}
if (min > 60) {
min = min - 60
hour = hour + 1
}
}
if ((val > 120 && val < 180) || val == 120) {
min = this.focusTimeList[0].substring(14, 16) * 1
min = min * 1 + val - 120
hour = this.focusTimeList[0].substring(11, 13) * 1
if (min == 60) {
min = 0
hour = this.focusTimeList[1].substring(11, 13) * 1
}
if (min > 60) {
min = min - 60
hour = hour + 1
}
}
if ((val > 180 && val < 240) || val == 180) {
min = this.focusTimeList[1].substring(14, 16) * 1
min = min * 1 + val - 180
hour = this.focusTimeList[1].substring(11, 13) * 1
if (min == 60) {
min = 0
hour = this.focusTimeList[2].substring(11, 13) * 1
}
if (min > 60) {
min = min - 60
hour = hour + 1
}
}
if ((val > 240 && val < 300) || val == 240) {
min = this.focusTimeList[2].substring(14, 16) * 1
min = min * 1 + val - 240
hour = this.focusTimeList[2].substring(11, 13) * 1
if (min == 60) {
min = 0
hour = this.focusTimeList[3].substring(11, 13) * 1
}
if (min > 60) {
min = min - 60
hour = hour + 1
}
}
if (val == 300) {
min = this.focusTimeList[3].substring(14, 16) * 1
min = min * 1 + val - 300
hour = this.focusTimeList[3].substring(11, 13) * 1
if (min > 60) {
min = min - 60
hour = hour + 1
}
}
if (hour < 10) {
hour = '0' + hour
}
if (min < 10) {
min = '0' + min
}
this.hour = hour
this.min = min
const time = hour + ':' + min
return time
} else {
hour = 0
min = 0
hour = this.focusTimeList[0].substring(11, 13)
min = this.focusTimeList[0].substring(14, 16)
const time = hour + ':' + min
return time
}
},
下面也是elementui自带函数大概意思就是你拖动划款松开鼠标触发的
schedule() {
this.searchValue.time = []
const start = this.focusTimeList[0]
const daydata = this.focusTimeListTwo[1].substring(0, 10)
const end = daydata + ' ' + this.hour + ':' + this.min + ':' + '00'
this.timer = daydata + ' ' + this.hour + ':' + this.min + ':' + '00'
this.searchValue.time.push(start)
this.searchValue.time.push(end)
this.loading = true
this.showFlag = true
this.recordList = []
if (this.valNew > this.valOld) {
var body = {
liveid: this.liveIdRow,
teacherid: this.TeacherIDRow,
start: this.searchValue.time[0],
end: this.searchValue.time[1]
}
return request({
method: 'get',
url: '/api/teacher/chat',
params: body
}).then(res => {
if (res.Content) {
this.messages = res.Content
this.messages.forEach(item => {
var num = parseInt(19 * Math.random())
item.img = require(`../../../assets/auter/icon-test_${num}.png`)
item.msgs = item.msg
.replace(/\[e\]em_/g, '<img src=../../../static/faces/em_')
.replace(/\[e\]/g, '.png>')
})
this.recordList = this.messages
this.loading = false
} else {
this.$message({
message: '无分析结果!',
type: 'warning'
})
this.loading = false
}
})
}
this.$nextTick(() => {
if (this.valNew < this.valOld) {
this.searchValue.time = []
this.searchValue.time[0] = this.datanewVI
this.searchValue.time[1] = this.dataoldVI
this.loading = true
this.showFlag = true
this.recordList = []
console.log(this.searchValue.time, 'watch')
const body = {
liveid: this.liveIdRow,
teacherid: this.TeacherIDRow,
start: this.searchValue.time[0],
end: this.searchValue.time[1]
}
return request({
method: 'get',
url: '/api/teacher/chat',
params: body
}).then(res => {
if (res.Content) {
this.messages = res.Content
this.messages.forEach(item => {
var num = parseInt(19 * Math.random())
item.img = require(`../../../assets/auter/icon-test_${num}.png`)
item.msgs = item.msg
.replace(/\[e\]em_/g, '<img src=../../../static/faces/em_')
.replace(/\[e\]/g, '.png>')
})
this.recordList = this.messages
this.loading = false
} else {
this.$message({
message: '无分析结果!',
type: 'warning'
})
this.loading = false
}
})
}
})
},
这个是计算函数 大概作用就是深拷贝
,
computed: {
datainit: function() {
var obj = {}
obj = JSON.parse(JSON.stringify(this.searchValue.time))
return obj
}
},
下面是监听函数 这就不用多说了 大家都懂监听
watch: {
datainit(newV, oldV) {
this.datanewV = newV[0]
this.datanewVI = newV[1]
this.dataoldV = oldV[0]
this.dataoldVI = oldV[1]
console.log(newV, 'newV,oldV', oldV)
},
val(newV, oldV) {
this.valNew = newV
this.valOld = oldV
}
},

贴代码是方便你们copy  下面就是带图讲解

完成上面这些你就可以随便滑动得到时间显示时间了

其实这个都很简单主要是取值问题是往后滑动没问题 怎么都能去取到值 就是往前拖动我怎么都拿不到前面的值  最后我想了办法把时间存起来深拷贝一下 再进行监听和新旧元素对比 这样就可以完美得到值了

这是刚开始进来

这是往前

这是往后

最后回去发现一开始进去就往左滑动会有bug进行改动改了就判断的地方

改成小于120还有大于120 这样就可以 但是bug还是有我服了   只能一开始进来右边滑块只能往右滑动 左边滑块只能往左滑动才能得到正确数据  一开始右边滑块往左移动和一开始进来左边滑块往右移动都拿不到正确数据 我枯了  求大神carry

3月31改动

终于经过我不懈努力 终于完美实现滑块怎么动都可以拿到值 我也是无意之中想到的  在元素上绑定ref利用ref来得到数值 特别特别的方便

给大家看改过的代码 只改动这里就够了之前写了太多多余的代码了

schedule() {
this.searchValue.time = []
const start = this.focusTimeList[0]
const daydata = this.focusTimeListTwo[1].substring(0, 10)
const end = daydata + ' ' + this.hour + ':' + this.min + ':' + '00'
this.searchValue.time.push(start)
this.searchValue.time.push(end)
this.loading = true
this.showFlag = true
this.recordList = []
this.$nextTick(() => {
this.searchValue.time = []
this.searchValue.time[0] = this.$refs.sliders.$children[0].formatValue
this.searchValue.time[1] = this.$refs.sliders.$children[1].formatValue
this.loading = true
this.showFlag = true
this.recordList = []
const body = {
liveid: this.liveIdRow,
teacherid: this.TeacherIDRow,
start: this.searchValue.time[0],
end: this.searchValue.time[1]
}
return request({
method: 'get',
url: '/api/teacher/chat',
params: body
}).then(res => {
if (res.Content) {
this.messages = res.Content
this.messages.forEach(item => {
var num = parseInt(19 * Math.random())
item.img = require(`../../../assets/auter/icon-test_${num}.png`)
item.msgs = item.msg
.replace(/\[e\]em_/g, '<img src=../../../static/faces/em_')
.replace(/\[e\]/g, '.png>')
})
this.recordList = this.messages
this.loading = false
} else {
this.$message({
message: '无分析结果!',
type: 'warning'
})
this.loading = false
}
})
})
},

终于大功告成了

感谢大家 要觉得不错右侧打赏一下把

elementUI slider组件,带范围选择实现双向绑定的更多相关文章

  1. vue2.X props 数据传递 实现组件内数据与组件外的数据的双向绑定

    vue2.0 禁止 子组件修改父组件数据 在Vue2中组件的props的数据流动改为了只能单向流动,即只能由组件外(调用组件方)通过组件的DOM属性attribute传递props给组件内,组件内只能 ...

  2. elementUI tree组件获取当前选择所有选中(check)和半选中(indeterminate)的节点

    网上查了半天,一大堆都说要改源码的,最后发现有方法不用改源码的 获取方法如下 this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHa ...

  3. vue.js组件之间通讯的数据双向绑定----父亲把数据传递给儿子,儿子更改数据后,重新发送给父亲,父亲数据更改后,属性会重新发送个儿子,儿子刷新新数据

    vue组件是相互独立的,如果要交互通讯,这时候,就需要组件之间数据互通了 往常我们讲的都是数据传递,子传父,父传子,都没有说子和父,父与子之间的数据互通 父亲传递给儿子数据,儿子触发一个父亲方法,将最 ...

  4. 如何在Vue2中实现组件props双向绑定

    Vue学习笔记-3 前言 Vue 2.x相比较Vue 1.x而言,升级变化除了实现了Virtual-Dom以外,给使用者最大不适就是移除的组件的props的双向绑定功能. 以往在Vue1.x中利用pr ...

  5. (复习)父子组件传值使用v-modal双向绑定,报错Avoid mutating a prop directly解决方案

    报错:Avoid mutating a prop directly since the value will be overwritten whenever the parent component. ...

  6. Blazor和Vue对比学习(基础1.5):双向绑定

    这章我们来学习,现代前端框架中最精彩的一部分,双向绑定.除了掌握原生HTML标签的双向绑定使用,我们还要在一个自定义的组件上,手撸实现双向绑定.双向绑定,是前两章知识点的一个综合运用(父传子.子传父) ...

  7. VUE JS 使用组件实现双向绑定

    1.VUE 前端简单介绍  VUE JS是一个简洁的双向数据绑定框架,他的性能超过ANGULARJS,原因是实现的机制和ANGULARJS 不同,他在初始化时对数据增加了get和set方法,在数据se ...

  8. element-ui dialog组件添加可拖拽位置 可拖拽宽高

    edge浏览器下作的gifhttp://www.lanourteam.com/%E6... 有几个点需要注意一下 每个弹窗都要有唯一dom可操作 指令可以做到 拖拽时要添加可拖拽区块 header 由 ...

  9. Elementui tabs组件内添加组件

    1. Elementui tabs组件内添加组件 1.1. 需求 今天的一个需求是在后台框架的基础上添加tab页,结果页面如下 原本上述红框内的内容是不存在的,直接点击左侧菜单栏进行页面跳转,现加了t ...

  10. 自定义组件实现双向绑定v-model

    自定义组件实现 v-model 双向绑定,首先要先明白 v-model,这个指令到底实现了什么? v-model实际做的事情就是:传入一个value属性值,然后监听input事件返回一个值,用该返回值 ...

随机推荐

  1. 力扣319(java)-灯泡开关(中等)

    题目: 初始时有 n 个灯泡处于关闭状态.第一轮,你将会打开所有灯泡.接下来的第二轮,你将会每两个灯泡关闭第二个. 第三轮,你每三个灯泡就切换第三个灯泡的开关(即,打开变关闭,关闭变打开).第 i 轮 ...

  2. 基于阿里云GPU云服务器的AIACC助力UC搜索业务性能提效380%,每年节省数千万成本

    简介: 用阿里云GPU计算实例来满足UC极致性价比需求 文丨阿里云神龙计算平台AI加速团队 & UC搜索架构部推理引擎团队 导语:作为国产行列里占有率排名第一的移动浏览器,UC浏览器自身承载着 ...

  3. 行业 SaaS 微服务稳定性保障实战

    简介: 对于Tob企业而言,稳定性即是生命线.那么,面对商户数目暴增, C 端场景业务不断扩展呢,F6汽车科技又是如何搭建可观测体系呢?一线负责人深度解读实际演进过程! 很多研发人员在日常工作中经常回 ...

  4. 阿里云云效技术专家:一文详解kubernetes下5种常见发布模式如何选择

    简介: Kubernetes下5场场景应用发布方式的选择,每种发布模式适合什么样的场景,以及如何在阿里云云效上高效落地. 作者:郑云龙,阿里云云效技术专家 Kubernetes面向通用场景提供了非常灵 ...

  5. Hologres揭秘:如何支持超高QPS在线服务(点查)场景

    简介: 本期我们将揭秘Hologres如何支持超高QPS在线服务(点查)场景. Hologres(中文名交互式分析)是阿里云自研的一站式实时数仓,这个云原生系统融合了实时服务和分析大数据的场景,全面兼 ...

  6. Go 语言网络库 getty 的那些事

    简介: Getty 维护团队不追求无意义的 benchmark 数据,不做无意义的炫技式优化,只根据生产环境需求来进行自身改进.只要维护团队在,Getty 稳定性和性能定会越来越优秀. 个人从事互联网 ...

  7. CSS属性继承问题,那些会被继承,哪些不继承?

    总的来能被继承的就是三大类 一,字体有关的的,font-开头的 二,文本有关的,text- 开头的 三,visibility , cursor 其它的基本都是不能被继承 比如说这个,你以为它继承了ma ...

  8. LVGL 日志

    一.启动日志 在 lv_conf.h 中将 LV_USE_LOG 设置为 1,如下图所示: 二.日志级别 在文件 lvgl/src/misc/lv_log.h 中定义了日志等级,等级是从小到大,所以 ...

  9. 第一讲 Cadence-于真博士课程简介

    第一讲 Cadence-于真博士课程简介 以工程化的思想来学习本课程,比较有效,从一个DSP开发板设计为例开始,做出PCB板,顺带学会Cadence软件操作,而不是仅仅学习软件. 前期准备工作,阅读配 ...

  10. vue从事件修饰符的角度讨论如何合理的设计一个弹窗

    1.设计思路:弹窗一般可以通过封装,单独设计一个组件,在需要的地方引入并通过变量布尔值进行展示和隐藏,方便使用者进行交互或提示信息 具体操作就是在给这个组件背景层添加全屏固定定位并设置透明度(cove ...