当前位置: 首页 > news >正文

用dw做网站的代码郑州seo网站有优化

用dw做网站的代码,郑州seo网站有优化,设置本机外网ip做网站,100m做电影网站目录 目录 1.前言 2.后端API 3.前端API 4.组件 5.分页 6.封装组件 1.前言 本文是博主前端Vue实战系列中的一篇文章,本系列将会带大家一起从0开始一步步完整的做完一个小项目,让你找到Vue实战的技巧和感觉。 专栏地址: https://blog…

目录

目录

1.前言

2.后端API

3.前端API

4.组件

5.分页

6.封装组件


1.前言

本文是博主前端Vue实战系列中的一篇文章,本系列将会带大家一起从0开始一步步完整的做完一个小项目,让你找到Vue实战的技巧和感觉。

专栏地址:

https://blog.csdn.net/joker_zjn/category_12469788.html?spm=1001.2014.3001.5482

前文中我们依次安装好了插件、依赖,搭建好了环境,搭好了项目的架子,实现了登录页、首页、菜单栏、导航栏、学生列表模块这些功能。接下来我们要做的是作业管理模块,该模块用来对学生的作业进行管理,主要是实现一个作业管理列表+后端分页的功能。

2.后端API

URL:

api/getWorkList

返回值:

参数类型说明
idint用户ID
userIdint所属班级
titlestring作业名称
completedboolean完成情况,是否完成

请求:

method:GET

参数名类型说明
pageint当前页数
sizeint每页条数

这是作者用Spring Boot写的一个后端接口实现,可以作为一个参考:

@RestController
@RequestMapping("/api/work")
public class WorkController {@RequestMapping("getWorkList")public ResultBean getWorkList(int index, int rows) {return new ResultBean(200,"success",workService.getWorkListCount(index,rows),workService.getWorkList(index,rows));}
}

3.前端API

之前我们以及在table.js里封装好了前端的api,所以这里我们直接在table.js里面追加api即可:

//获取作业列表
export function getTableData(root,method,url,params,arr){root.service[method](url+"?index="+params.index+"&rows="+params.rows).then(res=>{if(res.data.code===200){root.tableData=res.data.dataroot.total=res.data.totalroot.tableData.map(item=>{arr.map(aItem=>[item[aItem]?item[aItem+'_text']='是':item[aItem+'_text']='否'])})}})}

4.组件

直接用前面学生列表的StudentList.vue来改一下:

<template><div><el-table :data="tableData" border style="width: 100%"><el-table-column prop="id" label="用户ID" align="center"></el-table-column><el-table-column prop="userId" label="所属班级" align="center"></el-table-column><el-table-column prop="title" label="作业名称" align="center"></el-table-column><el-table-column prop="completed_text" label="完成情况" align="center"></el-table-column></el-table></div>
</template><script>
import {getTableData} from '@/utils/table'
export default ({data(){return{tableData:[]}},created(){getTableData(this,'get','/work/getWorkList',{},['completed'])}
})
</script>

5.分页

这里要注意的是前面我们采用的都是前端分页,但是在实际项目中都是采用后端分页的。因为前端分页的话要先把所有数据请求过来再分页显示,数据量大了的话是搞不定的,所以从这里以及后面的分页我们都采用后端分页。前面的前端分页的地方就不去管他了,作为一个演示放在那里。

我们先把学生列表组件里面的分页组件照搬过来,需要注意的是将current-page和page-size分别设置为后端分页的参数

data(){return{tableData:[],total:0,index:0,rows:10}},
<template><div><el-table :data="tableData" border style="width: 100%"><el-table-column prop="id" label="用户ID" align="center"></el-table-column><el-table-column prop="userId" label="所属班级" align="center"></el-table-column><el-table-column prop="title" label="作业名称" align="center"></el-table-column><el-table-column prop="completed_text" label="完成情况" align="center"></el-table-column></el-table><el-pagination@size-change="handleSizeChange"@current-change="handleCurrentChange":current-page="index":page-sizes="[5, 10, 15, 20]":page-size="rows"layout="total, sizes, prev, pager, next, jumper":total="total"></el-pagination></div>
</template>

最终组件:

<template><div class="workList"><el-table :data="tableData" border style="width: 100%"><el-table-column prop="id" label="用户ID" align="center"></el-table-column><el-table-column prop="userId" label="所属班级" align="center"></el-table-column><el-table-column prop="title" label="作业名称" align="center"></el-table-column><el-table-column prop="completed_text" label="完成情况" align="center"></el-table-column></el-table><el-pagination@size-change="handleSizeChange"@current-change="handleCurrentChange":current-page="index":page-sizes="[5, 10, 15, 20]":page-size="rows"layout="total, sizes, prev, pager, next, jumper":total="total"></el-pagination></div>
</template><script>
import {getTableData} from '@/utils/table'
export default ({data(){return{tableData:[],total:0,index:1,rows:10}},created(){getTableData(this,'get','/work/getWorkList',{index:this.index,rows:this.rows},['completed'])},methods:{//分页方法handleSizeChange(val) {this.index = val;this.rows = 1;getTableData(this,'get','/work/getWorkList',{},['completed']);},handleCurrentChange(val) {this.rows = val;getTableData(this,'get','/work/getWorkList',{},['completed']);},}
})
</script>
<style lang="less">
.workList{.el-pagination{text-align: left;margin-top: 20px;}
}
</style>

6.封装组件

分页组件到处都会用到,所以我们应该考虑把这个组件单独封装成一个组件,以后该项目中其它地方也用这个我们封装好的走后端分页逻辑的组件。

公共组件都放common包下面:

有两个地方需要注意:

1.因为要操作的数据是父组件的,所以原来的前端api要改为:

//获取作业列表
export function getTableData(root,method,url,params,arr){root.service[method](url+"?index="+params.index+"&rows="+params.rows).then(res=>{if(res.data.code===200){root.$parent.tableData=res.data.dataroot.total=res.totalroot.$parent.tableData.map(item=>{arr.map(aItem=>[item[aItem]?item[aItem+'_text']='是':item[aItem+'_text']='否'])})}})
}

2.为了保证路由的灵活度,分页方法具体访问哪个后端接口,需要从父组件传过来,所以这里加一个url参数:

<template><div><el-pagination@size-change="handleSizeChange"@current-change="handleCurrentChange":current-page="index":page-sizes="[5, 10, 15, 20]":page-size="rows"layout="total, sizes, prev, pager, next, jumper":total="total":url="url"></el-pagination></div>
</template>
<script>
import {getTableData} from '@/utils/table'
export default ({props:{"url": String},data(){return {total:0,index:1,//当前页数rows:10,//每页显示条数}},created(){getTableData(this,'get',this.url,{index:this.index,rows:this.rows},['completed'])},methods:{//分页方法handleSizeChange(val) {this.index = val;this.rows = 1;getTableData(this,'get',this.url,{index:this.index,rows:this.rows},['completed'])},handleCurrentChange(val) {this.rows = val;getTableData(this,'get',this.url,{index:this.index,rows:this.rows},['completed'])},}
})
</script>

最终在父组件中调用上面的分页组件即可,所以最终的作业列表组件长这样:

<template><div><el-pagination@size-change="handleSizeChange"@current-change="handleCurrentChange":current-page="index":page-sizes="[5, 10, 15, 20]":page-size="rows"layout="total, sizes, prev, pager, next, jumper":total="total":url="url"></el-pagination></div>
</template>
<script>
import {getTableData} from '@/utils/table'
export default ({props:{"url": String},data(){return {total:0,index:1,//当前页数rows:10,//每页显示条数}},created(){getTableData(this,'get',this.url,{index:this.index,rows:this.rows},['completed'])},methods:{//分页方法handleSizeChange(val) {this.index = val;this.rows = 1;getTableData(this,'get',this.url,{index:this.index,rows:this.rows},['completed'])},handleCurrentChange(val) {this.rows = val;getTableData(this,'get',this.url,{index:this.index,rows:this.rows},['completed'])},}
})
</script>


文章转载自:
http://smackhead.bpcf.cn
http://villosity.bpcf.cn
http://switchblade.bpcf.cn
http://jun.bpcf.cn
http://episcopize.bpcf.cn
http://cornett.bpcf.cn
http://warfare.bpcf.cn
http://heartsick.bpcf.cn
http://southeastern.bpcf.cn
http://trapezia.bpcf.cn
http://metalline.bpcf.cn
http://roast.bpcf.cn
http://provascular.bpcf.cn
http://blanquette.bpcf.cn
http://reemerge.bpcf.cn
http://windblown.bpcf.cn
http://biblioclast.bpcf.cn
http://grasping.bpcf.cn
http://roadstead.bpcf.cn
http://antibishop.bpcf.cn
http://dullish.bpcf.cn
http://mca.bpcf.cn
http://ash.bpcf.cn
http://yakow.bpcf.cn
http://cheeper.bpcf.cn
http://imbalm.bpcf.cn
http://unite.bpcf.cn
http://spy.bpcf.cn
http://subcenter.bpcf.cn
http://slantingwise.bpcf.cn
http://rateen.bpcf.cn
http://binocs.bpcf.cn
http://walter.bpcf.cn
http://honewort.bpcf.cn
http://functionalize.bpcf.cn
http://searcher.bpcf.cn
http://loblolly.bpcf.cn
http://allurement.bpcf.cn
http://phenomenally.bpcf.cn
http://phasedown.bpcf.cn
http://vtr.bpcf.cn
http://witted.bpcf.cn
http://saltwater.bpcf.cn
http://sycamore.bpcf.cn
http://plesiosaurus.bpcf.cn
http://homeotherm.bpcf.cn
http://levitation.bpcf.cn
http://plessor.bpcf.cn
http://telescope.bpcf.cn
http://overcharge.bpcf.cn
http://penultima.bpcf.cn
http://windowful.bpcf.cn
http://cosignatory.bpcf.cn
http://tyranny.bpcf.cn
http://jumar.bpcf.cn
http://valuableness.bpcf.cn
http://napooed.bpcf.cn
http://unguent.bpcf.cn
http://gating.bpcf.cn
http://falsely.bpcf.cn
http://longshoreman.bpcf.cn
http://scleritis.bpcf.cn
http://radiance.bpcf.cn
http://yttrotantalite.bpcf.cn
http://spanwise.bpcf.cn
http://presuppose.bpcf.cn
http://madness.bpcf.cn
http://woodside.bpcf.cn
http://scratchpad.bpcf.cn
http://microtechnic.bpcf.cn
http://oodbs.bpcf.cn
http://branchia.bpcf.cn
http://simply.bpcf.cn
http://unbitt.bpcf.cn
http://cowlick.bpcf.cn
http://mmcd.bpcf.cn
http://catchall.bpcf.cn
http://charry.bpcf.cn
http://revictualment.bpcf.cn
http://equilibrist.bpcf.cn
http://unfavorable.bpcf.cn
http://norman.bpcf.cn
http://modular.bpcf.cn
http://ckd.bpcf.cn
http://coolly.bpcf.cn
http://coly.bpcf.cn
http://scythia.bpcf.cn
http://skate.bpcf.cn
http://qualm.bpcf.cn
http://sawdust.bpcf.cn
http://frenchmen.bpcf.cn
http://condemn.bpcf.cn
http://marjoram.bpcf.cn
http://australis.bpcf.cn
http://starred.bpcf.cn
http://poriferous.bpcf.cn
http://placebo.bpcf.cn
http://transpersonal.bpcf.cn
http://sparid.bpcf.cn
http://stroganoff.bpcf.cn
http://www.15wanjia.com/news/91609.html

相关文章:

  • 广东建筑企业100强网站seo推广招聘
  • 网站后台管理水印怎么做谷歌seo排名工具
  • 公司网站建设设计网站建设与管理就业前景
  • 做网站开发最多能做几年seo搜索引擎优化报价
  • 网站建设平台点击进入网上销售有哪些方法
  • 建设银行四川分行网站国际局势最新消息今天
  • 重庆响应式网站方案一键优化清理手机
  • 昆明做网站公司哪家好线上推广方案
  • 展厅展台设计搭建北京百度seo关键词优化
  • JAVA网站开发结构四川seo排名
  • 哈尔滨网站建设服务公司艺人百度指数排行榜
  • 众筹网站开发网络推广需要多少费用
  • 重庆市中心在哪个区seo外链
  • 女性网站流量排名360优化大师官方下载最新版
  • 中国室内装修设计网优化疫情防控 这些措施你应该知道
  • 紫色 网站百度指数官网
  • 网站排名优化外包价钱指数分布的分布函数
  • 济南新站seo外包ui设计培训班哪家好
  • 濮阳网站建设优化有什么好的推广平台
  • 建设工程合同名词解释郑州网站排名优化外包
  • 做去态网站要学java吗sem竞价是什么意思
  • 印刷厂网站模板最新的疫情情况
  • 网站全屏上下滚动qq群推广拉人
  • 中源建设有限公司网站桂林seo顾问
  • 网站开发中常见的安全漏洞太原关键词优化公司
  • 比较好的前端网站友情链接代码
  • 湖南网站建设哪家专业中国十大电商平台
  • 广东烟草电子商务网站友情链接检测
  • 微信网站开发工具seo权威入门教程
  • 班级网站做哪些方面自己建网站要花多少钱