vue自定义指令获取焦点及过滤器修改时间
<template id="comp3">
<div id="app">
<model :list="selectedlist" :isactive="isActive" v-cloak @change="changeOverlay" @modify="add" @msearch="search"></model>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">网课管理</h3>
</div>
<div class="panel-body form-inline">
<label>
搜索名称关键字:
<!-- 自定义获取焦点 指令 -->
<input type="text" class="form-control" v-focus v-model="keywords" id="search">
<input type="button" value="搜索" class="btn btn-primary" />
</label>
<label>
ID:
<input type="text" class="form-control" v-model="id">
</label>
<label>
网课名称:
<input type="text" class="form-control" v-model="subClassifyName" @keyup.enter="add">
</label>
<input type="button" value="添加" class="btn btn-primary" @click="add()" />
</div>
</div>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th class="text-center">网课ID</th>
<th class="text-center">网课名称</th>
<th class="text-center">创建时间</th>
<th class="text-center">更新时间</th>
<th class="text-center">操作</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) of search(keywords)" :key="item.id">
<td class="text-center" v-text="item.id"></td>
<td class="text-center" v-text="item.subClassifyName"></td>
<td class="text-center" v-text="">{{item.createTime | dateFormat}}</td>
<td class="text-center" v-text="">{{item.updateTime | dateFormat}}</td>
<td class="text-center">
<!--data-toggle="modal" data-target="#update"-->
<a href="#" @click="showOverlay(index)">
<input type="button" data-toggle="modal" data-target="#compmodify_dialog" class="btn btn-primary" value="修改" />
</a>
<a href="#" @click.prevent="del(item.id)">
<input type="button" class="btn btn-danger" value="删除" />
</a>
</td>
</tr>
</tbody>
</table>
<!-- 底部索引 -->
<div class="box-pagination">
<ul class="pagination">
<li><a href="#" aria-label="Previous" @click="getpageinfo(1)">首页</a></li>
</ul>
<ul class="pagination">
<li><a href="#" @click="getprepageinfo()">«</a></li>
</ul>
<ul v-for="i in page" class="pagination">
<li><a href="#" @click="getpageinfo(i)">{{i}}</a></li>
</ul>
<ul class="pagination">
<li><a href="#" @click="getaftpageinfo()">»</a></li>
</ul>
<ul class="pagination">
<li><a href="#" aria-label="Previous" @click="getpageinfo(page)">尾页</a></li>
</ul>
</div>
</div>
</template>
template
// 网课管理 (comp3)
var register = {
template: '#comp3',
data() {
return {
isActive: false,
selected: -1,
selectedlist: {},
classifyName: '',
keywords: '',
id: '',
subClassifyName: '',
creatTime: '',
updateTime: '', pagenum: '',
page: '', list: [],
}
},
props: ['clist'],
methods: {
// 修改数据
showOverlay(index) {
this.selected = index;
this.selectedlist = this.list[index];
this.changeOverlay();
},
// 点击保存按钮
modify(arr) {
if (this.selected > -1) {
Vue.set(this.list, this.selected, arr);
this.selected = -1;
} else {
this.list.push(arr);
}
this.setSlist(this.list);
this.changeOverlay();
},
// 添加
add: function() {
//获取id subClassifyName 加入到数组
var car = {
id: this.id,
subClassifyName: this.subClassifyName,
createTime: new Date()
}
this.list.push(car)
/*重置id subClassifyName 让对话栏里值空*/
this.id = this.subClassifyName = ''
},
// 发起get请求后通过.then获取服务器返回的内容
getpageinfo(pagenum) {
this.pagenum = pagenum;
this.$http.get('http://10.0.41.100:8096/course/list/' + pagenum).then(function(result) {
this.list = result.body.list
this.page = Math.ceil(result.body.total / 5)
/*alert(Math.ceil(result.body.total/5))*/
})
},
getprepageinfo() {
if (this.pagenum > 0) {
this.pagenum = this.pagenum - 1;
}
/*alert(pagenum)*/
this.$http.get('http://10.0.41.100:8096/course/list/' + this.pagenum).then(function(result) {
this.list = result.body.list
this.page = Math.ceil(result.body.total / 5)
})
},
getaftpageinfo() {
if (this.pagenum < this.page) {
this.pagenum = this.pagenum + 1;
}
/*alert(pagenum)*/
this.$http.get('http://10.0.41.100:8096/course/list/' + this.pagenum).then(function(result) {
this.list = result.body.list
this.page = Math.ceil(result.body.total / 5)
}) },
getinfo() {
this.$http.get('http://10.0.41.100:8096/course/list/' + '1').then(function(result) {
this.list = result.body.list
this.page = Math.ceil(result.body.total / 5)
/*alert(Math.ceil(result.body.total/5))*/
}) },
/*根据id找到数据用list的 splice方法删除*/
del(id) {
this.list.some((item, i) => {
if (item.id == id) {
this.list.splice(i, 1)
return true;
}
})
},
/*更改覆盖*/
changeOverlay() {
// 重置控件状态
this.selected = -1;
this.isActive = !this.isActive;
this.createTime = new Date();
},
/*查询*/
search(keywords) {
/*includes() 检索该字符串中是否包含指定字符 是 返回*/
return this.list.filter(item => {
if (item.subClassifyName.includes(keywords)) {
return item
}
})
}
},
created() { // 模板加载完成后立刻请求数据
this.getinfo();
}
}
// 网课管理 的模态框
Vue.component('model', {
props: ['list', 'isactive', 'selectedlist', ],
template: "#compmodify",
computed: {
modifylist() {
return this.list;
}
},
methods: {
changeActive() {
this.$emit('change');
},
modify() {
this.$emit('add', this.modifylist);
}
}
});
vue
/*1、日期过虑器--全局*/
Vue.filter('dateFormat', function(dateStr, pattern = "") {
// 根据给定字符串 得到特定时间 yyyy-mm-dd
var dt = new Date(dateStr)
var y = dt.getFullYear()
var m = dt.getMonth() + 1 //month从0开始
var d = dt.getDate() if(pattern.toLowerCase() === 'yyyy-mm-dd') { //toLowerCase() 转换成小写
return `${y}-${m}-${d}`
} else {
var hh = dt.getHours()
var mm = dt.getMinutes()
var ss = dt.getSeconds()
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
}
})
/*2、自动获取光标--用Vue.directive()定义全局指令*/
Vue.directive('focus', {
inserted: function(el) { // 表示元素插入到DOM中的时候,会执行inserted函数
el.focus()
},
})
Js
vue自定义指令获取焦点及过滤器修改时间的更多相关文章
- vue自定义指令实例使用(实例说明自定义指令的作用)
在写vue项目的时候,我们经常需要对后台返回的数据进行大量的渲染操作,其中就包含了大量的对特殊数据的进一步处理,比如说时间戳.图片地址.特殊数据显示等等特殊数据处理改进. 其实遇到这种情况,通过Vue ...
- Vue自定义指令使用方法详解 和 使用场景
Vue自定义指令的使用,具体内容如下 1.自定义指令的语法 Vue自定义指令语法如下: Vue.directive(id, definition) 传入的两个参数,id是指指令ID,definitio ...
- vue 自定义指令的使用案例
参考资料: 1. vue 自定义指令: 2. vue 自定义指令实现 v-loading: v-loading,是 element-ui 组件库中的一个用于数据加载过程中的过渡动画指令,项目中也很少需 ...
- vue自定义指令clickoutside使用以及扩展用法
vue自定义指令clickoutside使用以及扩展用法 产品使用vue+element作为前端框架.在功能开发过程中,难免遇到使用element的组件没办法满足特殊的业务需要,需要对其进行定制,例如 ...
- vue自定义指令clickoutside扩展--多个元素的并集作为inside
都是个人理解,如果发现错误,恳请大家批评指正,谢谢.还有我说的会比较啰嗦,因为是以自身菜鸡水平的视角来记录学习理解的过程,见谅. 1.前言 产品使用vue+element作为前端框架.在功能开发过程中 ...
- Vue自定义指令使用场景
当你第一次接触vue的时候,一定会使用到其中的几个指令,比如:v-if.v-for.v-bind...这些都是vue为我们写好的,用起来相当的爽.如果有些场景不满足,需要我们自己去自定义,那要怎么办呢 ...
- vue 自定义指令的魅力
[第1103期]vue 自定义指令的魅力 点点 前端早读课 2017-11-08 前言 很多事情不能做过多的计划,因为计划赶不上变化.今日早读文章由富途@点点翻译分享. 正文从这开始- 在你初次接触一 ...
- vue自定义指令
Vue自定义指令: Vue.directive('myDr', function (el, binding) { el.onclick =function(){ binding.value(); } ...
- vue自定义指令(Directive中的clickoutside.js)的理解
阅读目录 vue自定义指令clickoutside.js的理解 回到顶部 vue自定义指令clickoutside.js的理解 vue自定义指令请看如下博客: vue自定义指令 一般在需要 DOM 操 ...
随机推荐
- 使用AnnotationConfigApplicationContext注册配置类
1. AnnotationConfigApplicationContext功能 该类可以实现基于Java的配置类加载自定义在Spring的应用上下文的bean. 1.1 使用方式一:在构造方法中完成注 ...
- 词根——rect
词根rect:直 线索链 来源于简单词right righta.正确的,直的,右的 (正和直是不分的)n. 右,权利ad.正确地,在右边 rectifyv. 纠正,整顿把它直起来 rect+ify=直 ...
- css常用小知识点汇总(一)
1.文本过多溢出,怎么让他隐藏变成点点点(...)呢? text-overflow:ellipsis;overflow:hidden;display:-webkit-box;-webkit-line- ...
- vue.js动态表格增删改代码
新建一个html文件,内容如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"& ...
- C# Asp.NET实现上传大文件(断点续传)
以ASP.NET Core WebAPI 作后端 API ,用 Vue 构建前端页面,用 Axios 从前端访问后端 API ,包括文件的上传和下载. 准备文件上传的API #region 文件上传 ...
- Spring Cloud架构教程 (七)消息驱动的微服务(核心概念)【Dalston版】
下图是官方文档中对于Spring Cloud Stream应用模型的结构图.从中我们可以看到,Spring Cloud Stream构建的应用程序与消息中间件之间是通过绑定器Binder相关联的,绑定 ...
- tomcat安全配置参考
0x01 基本配置 1 删除默认目录 安装完tomcat后,删除$CATALINA_HOME/webapps下默认的所有目录文件 rm -rf /srv/apache-tomcat/webapps/ ...
- git pull失误提交
git pull 提示错误,Your local changes to the following files would be overwritten by merge 到公司后本来打算git pu ...
- 爬虫 ---- BeautifulSoup的基础使用
#BeautifulSoup的基础使用from bs4 import BeautifulSoup #导入bs4库 html = "<p class='stylecss'>< ...
- wow64 32位进程中切换64位模式,取回64位寄存器值
32位dbg中编辑的: 7711E9D3 | 6A | | 7711E9D5 | E8 | 7711E9DA | | | 7711E9DE | CB | ret far | 6A E8 CB 64位d ...