vue中的ElementUI的使用详解

登录+sessionStorage

效果展示

登录成功后会把用户id存入前端的sessionStorage,拦截器会根据是否存在用户id来进行拦截
也可以将用户权限存入sessionStorage,然后当访问某个页面的时候在created方法中判断是否具有权限

<template>
	<div class="login-wrap">
		<el-form class="login-container" ref="loginFormRef" :model="loginForm">
			<h1 class="title">用户登陆</h1>
			<el-form-item label="">
				<el-input type="text" placeholder="用户账号" v-model="loginForm.username" autocomplete="off"></el-input>
			</el-form-item>
			<el-form-item label="">
				<el-input type="text" placeholder="用户密码" v-model="loginForm.password" autocomplete="off"></el-input>
			</el-form-item>

			<el-form-item >
				<el-radio-group v-model="loginForm.resource">
					<el-radio label="管理员"></el-radio>
					<el-radio label="普通用户"></el-radio>
				</el-radio-group>
			</el-form-item>

			<el-form-item>
				<template slot-scope="scope">
					<el-button type="primary" @click="doLogin()" style="width: 100%;">用户登录</el-button>
					<!-- <el-button style="width: 48%;" @click="gotoRegister" >用户注册</el-button> -->
				</template>
			</el-form-item>
			<!-- <el-row style="text-align: center;">

                <el-link @click="gotoRegister()">用户注册</el-link>
                <el-link>忘记密码</el-link>

            </el-row> -->
		</el-form>
	</div>
</template>

<script>
	export default {
		data: function() {
			return {

				loginForm: {
					username: '',
					password: '',
					resource: ''
				}
			}
		},

		methods: {
			gotoRegister: function() {
				this.$router.push({
					name: 'register'
				});
			},
			doLogin() {
				let resource = this.loginForm.resource
				this.$refs.loginFormRef.validate(async valid => {
					if (!valid) return;
					if (resource == "管理员") {
						const {
							data: res
						} = await this.axios.post("http://localhost:8088/loginadmin", this.loginForm)

						if (res) {
							this.$message.success("管理员登录成功")
							sessionStorage.setItem("personid","ljhjiayou")

							this.$router.push({
								path: "/dong"
							});
						} else {
							this.$message.error("账号或密码错误")
						}
						//普通用户登录
					}else{

						const {
							data: res
						} = await this.axios.post("http://localhost:8088/loginuser", this.loginForm)

						if (res) {
							console.log(res)
							this.$message.success("普通用户登录成功")
							sessionStorage.setItem("personid",res)
							this.$router.push({
								path: "/person"
							});
						} else {
							this.$message.error("账号或密码错误")
						}
					}

				})
			}
		}
	}
</script>
//scoped="scoped" 表示样式仅仅规范当前VUE
<style scoped="scoped">
	.login-wrap {
		box-sizing: border-box;
		width: 100%;
		height: 100%;
		padding-top: 10%;
		background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+Cjxzdmcgd2lkdGg9IjEzNjFweCIgaGVpZ2h0PSI2MDlweCIgdmlld0JveD0iMCAwIDEzNjEgNjA5IiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPgogICAgPCEtLSBHZW5lcmF0b3I6IFNrZXRjaCA0Ni4yICg0NDQ5NikgLSBodHRwOi8vd3d3LmJvaGVtaWFuY29kaW5nLmNvbS9za2V0Y2ggLS0+CiAgICA8dGl0bGU+R3JvdXAgMjE8L3RpdGxlPgogICAgPGRlc2M+Q3JlYXRlZCB3aXRoIFNrZXRjaC48L2Rlc2M+CiAgICA8ZGVmcz48L2RlZnM+CiAgICA8ZyBpZD0iQW50LURlc2lnbi1Qcm8tMy4wIiBzdHJva2U9Im5vbmUiIHN0cm9rZS13aWR0aD0iMSIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj4KICAgICAgICA8ZyBpZD0i6LSm5oi35a+G56CB55m75b2VLeagoemqjCIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTc5LjAwMDAwMCwgLTgyLjAwMDAwMCkiPgogICAgICAgICAgICA8ZyBpZD0iR3JvdXAtMjEiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDc3LjAwMDAwMCwgNzMuMDAwMDAwKSI+CiAgICAgICAgICAgICAgICA8ZyBpZD0iR3JvdXAtMTgiIG9wYWNpdHk9IjAuOCIgdH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IgY3k9IjMwLjMzMzMzMzMiIHI9IjUuODMzMzMzMzMiPjwvY2lyY2xlPgogICAgICAgICAgICAgICAgICAgIDxjaXJjbGUgaWQ9Ik92YWwtNS1Db3B5LTUiIGZpbGw9IiNFMEI0QjciIGN4PSIxNzUuNTgzMzMzIiBjeT0iMjMyLjc1IiByPSI1LjI1Ij48L2NpcmNsZT4KICAgICAgICAgICAgICAgIDwvZz4KICAgICAgICAgICAgPC9nPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+);
		/* background-color: #112346; */
		background-repeat: no-repeat;
		background-position: center right;
		background-size: 100%;
	}

	.login-container {
		border-radius: 10px;
		margin: 0px auto;
		width: 350px;
		padding: 30px 35px 15px 35px;
		background: #fff;
		border: 1px solid #eaeaea;
		text-align: left;
		box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.1);
	}

	.title {
		margin: 0px auto 40px auto;
		text-align: center;
		color: #505458;
	}
</style>

分页表格

效果展示

分页这一块是难点也是重点!!!
handleSizeChange方法选择分页大小
handleCurrentChange方法选择第几页
loadData调用后端API接口获取分页的数据

<template>
	<div>
		<el-table :data="tableData" border style="width: 100%">
			<el-table-column fixed prop="id" label="新闻id" width="150">
			</el-table-column>
			<el-table-column prop="typeid" label="新闻标题" width="200">
			</el-table-column>
			<el-table-column prop="otherid" label="新闻摘要" width="200"> </el-table-column>
			<el-table-column prop="money" label="新闻内容" width="200">
			</el-table-column>
			<el-table-column prop="datetime" label="新闻发布时间" width="150"> </el-table-column>
			<el-table-column fixed="right" label="操作" width="200">
				<template slot-scope="scope">
					<el-button @click="updateExercise(scope.row)" size="mesdium" type="primary">修改</el-button>
					<el-button @click="deleteExercise(scope.row)" type="warning" size="medium">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<div class="block">
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="currentPage" :page-sizes="[5, 10, 15, 20]" :page-size="pageSize"
				layout="total, sizes, prev, pager, next, jumper" :total="totalCount">
			</el-pagination>
		</div>
	</div>
</template>
<script>
	export default {
		methods: {
			handleSizeChange(val) {
				//console.log(val)
				this.pageSize = val;
				this.loadData( this.currentPage, this.pageSize);
			},
			handleCurrentChange(val) {
				console.log(val)
				this.currentPage = val;
				this.loadData( this.currentPage, this.pageSize);
			},
			//从服务器读取数据
			loadData: function(pageNum, pageSize) {
				let _this = this;
				console.log(this.pageNum)
				this.axios.get("http://localhost:8088/records/querystudentbypage?pageNum=" + pageNum +
					"&pageSize=" + this.pageSize).then(function(res) {
					//console.log(res.data.pagestudentdata.list)
					_this.tableData = res.data.pagestudentdata.list;
					_this.totalCount = res.data.number;

				}, function() {
					console.log('failed');
				});
			},

		},
		data() {
			return {
				// currentPage1: 5,
				// currentPage2: 5,
				// currentPage3: 5,
				// currentPage4: 4,
				currentPage: 1,
				tableData: null,
				pageSize: 5,
				totalCount: 15,
				pageNum: 1,
			};
		},
		created() {
			// let _this = this;
			// axios.get("http://localhost:8088/records").then(function(response) {
			// 	_this.tableData = response.data
			// })
			this.loadData(this.pageNum,this.pageSize)
		},
	}
</script>

后端

@ResponseBody
    @RequestMapping(value = "/querystudentbypage", method = RequestMethod.GET)
    public Map<String, Object> querystudentbypage(@RequestParam(value="pageNum")int pageNum, @RequestParam(value="pageSize")int pageSize)
    {
        PageHelper.startPage(pageNum,pageSize);
        List<Records> courses = recordsMapper.selectList(null);
        PageInfo<Records> page = new PageInfo<>(courses);
        System.out.println("---------------"+page);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pagestudentdata", page);
        map.put("number", page.getTotal());
        return map;
    }

参考链接

开关+标签页

效果展示

开关的主要方法 switchChange
标签页不难,如果看不懂下面代码,可以参考官方文档

前端开关主要代码

 <el-table-column prop="name" label="是否冻结" width="150">
		  	<template slot-scope="scope">
		  		<el-switch v-model="scope.row.statusid" :active-value="1" :inactive-value="2"
		  			@change="switchChange($event, scope.row)" active-color="#13ce66"
		  			inactive-color="#ff4949"></el-switch>
		  	</template>
 </el-table-column>

完整代码

<template>
  <el-tabs v-model="activeName" @tab-click="handleClick">
    <el-tab-pane label="所有账户" name="first">
		<el-table :data="tableData" border style="width: 100%">
		  <el-table-column fixed prop="accoundid" label="账户id" width="150">
		  </el-table-column>
		  <el-table-column prop="password" label="密码" width="200">
		  </el-table-column>
		  <el-table-column prop="balance" label="余额" width="200"> </el-table-column>
		  <el-table-column prop="name" label="是否冻结" width="150">
		  	<template slot-scope="scope">
		  		<el-switch v-model="scope.row.statusid" :active-value="1" :inactive-value="2"
		  			@change="switchChange($event, scope.row)" active-color="#13ce66"
		  			inactive-color="#ff4949"></el-switch>
		  	</template>
		  </el-table-column>
		  <el-table-column prop="personid" label="personid" width="200">
		  </el-table-column>
		  <el-table-column fixed="right" label="操作" width="200">
		    <template slot-scope="scope">
		      <el-button @click="deleteExercise(scope.row)" type="warning" size="medium"
		        >删除</el-button
		      >
		    </template>
		  </el-table-column>
		</el-table>
	</el-tab-pane>
    <el-tab-pane label="被冻结的账户" name="second">
		<el-table :data="tableDatab" border style="width: 100%">
		  <el-table-column fixed prop="accoundid" label="账户id" width="150">
		  </el-table-column>
		  <el-table-column prop="personinfo.realname" label="名字" width="200">
		  </el-table-column>
		  <el-table-column prop="password" label="密码" width="200">
		  </el-table-column>
		  <el-table-column prop="balance" label="余额" width="200"> </el-table-column>

		  <el-table-column fixed="right" label="操作" width="200">
		    <template slot-scope="scope">
				<el-button @click="qiyong(scope.row)" type="warning" size="medium"
				  >启用</el-button
				>
		    </template>
		  </el-table-column>
		</el-table>
	</el-tab-pane>
    <el-tab-pane label="已启用的账户" name="third">
		<el-table :data="tableDatabc" border style="width: 100%">
		  <el-table-column fixed prop="accoundid" label="账户id" width="150">
		  </el-table-column>
		  <el-table-column prop="personinfo.realname" label="名字" width="200">
		  </el-table-column>
		  <el-table-column prop="password" label="密码" width="200">
		  </el-table-column>
		  <el-table-column prop="balance" label="余额" width="200"> </el-table-column>

		  <el-table-column fixed="right" label="操作" width="200">
		    <template slot-scope="scope">
		      <el-button @click="dongjie(scope.row)" type="warning" size="medium"
		        >冻结</el-button
		      >
		    </template>
		  </el-table-column>
		</el-table>
	</el-tab-pane>
  </el-tabs>
</template>
<script>
  export default {
    data() {
      return {
		tableData: null,
		tableDatab: null,
		tableDatabc: null,
        activeName: 'first'
      };
    },
    methods: {
      handleClick(tab, event) {
        console.log(tab, event);
      },
	  switchChange(e, data) {
	  	if (e == 1) {
	  		axios.get('http://localhost:8088/accounts/kaiqi/' + data.accoundid).then((res) => {
	  			this.$message({
	  				message: "开启成功",
	  				type: "success"
	  			});
	  			// location.reload()
	  		});
	  	} else if (e == 2) {
	  		axios.get('http://localhost:8088/accounts/dongjie/' + data.accoundid).then((res) => {
	  			this.$message({
	  				message: "冻结成功",
	  				type: "success"
	  			});
	  			// location.reload()
	  		});
	  	}

	  },
	  dongjie(row) {
	    let _this=this
	    this.$confirm('是否确定冻结'+row.personinfo.realname+'的账户?','冻结账户',{
	    	confirmButtonText: '确定',
	    	cancelButtonText: '取消',
	    	type: 'warning'
	    }).then(()=>{
	    	axios.get('http://localhost:8088/accounts/dongjie/'+row.accoundid).then(function (response){
	    		if(response.data){
	    			_this.$alert(row.personinfo.realname+'的账户冻结成功!', '冻结账户',{
	    				confirmButtonText: '确定',
	    				callback: action =>{
	    					location.reload()
	    				}
	    			});
	    		}
	    	})
	    }).catch(()=>{

	    });
	  },
	  qiyong(row) {
	    let _this=this
	    this.$confirm('是否确定启用'+row.personinfo.realname+'的账户?','启用账户',{
	    	confirmButtonText: '确定',
	    	cancelButtonText: '取消',
	    	type: 'warning'
	    }).then(()=>{
	    	axios.get('http://localhost:8088/accounts/kaiqi/'+row.accoundid).then(function (response){
	    		if(response.data){
	    			_this.$alert(row.personinfo.realname+'的账户启用成功!', '启用账户',{
	    				confirmButtonText: '确定',
	    				callback: action =>{
	    					location.reload()
	    				}
	    			});
	    		}
	    	})
	    }).catch(()=>{

	    });
	  },
	  deleteExercise(row) {
	    let _this=this
	    this.$confirm('是否确定删除账户'+row.accoundid+'?','删除账户',{
	    	confirmButtonText: '确定',
	    	cancelButtonText: '取消',
	    	type: 'warning'
	    }).then(()=>{
	    	axios.delete('http://localhost:8088/accounts/'+row.accoundid).then(function (response){
	    		if(response.data){
	    			_this.$alert(row.accoundid+'账户删除成功!', '删除账户',{
	    				confirmButtonText: '确定',
	    				callback: action =>{
	    					location.reload()
	    				}
	    			});
	    		}
	    	})
	    }).catch(()=>{

	    });
	  },
    },
	created(){
		let _this=this;
		axios.get("http://localhost:8088/accounts").then(function (response){
			_this.tableData=response.data
		})
		axios.get("http://localhost:8088/accounts/dongjie").then(function (response){
			_this.tableDatab=response.data
		})
		axios.get("http://localhost:8088/accounts/qiyong").then(function (response){
			_this.tableDatabc=response.data
		})
	},
  };
</script>

前端拦截器

判断路由是否需要登录权限

main.js

router.beforeEach((to, from, next) => {
	// next()
	if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
		if (sessionStorage.getItem("personid")) {
			next()
		} else {
			// 未登录,跳转到登录页面
			next('/')
		}
	} else {
		next()
	}
})

route.js

在路由中添加 meta: requireAuth:true
表示是否需要登录才能访问

{
		path: '/listxw',
		name: '新闻管理',
		component: Index,
		show: true,
		meta: {
			requireAuth: true
		},

		redirect: "/listxw",
		children: [{
				path: "/addxw",
				name: "添加新闻",
				component: addxw,
				meta: {
					requireAuth: true
				},

			},
			{
				path: "/updatexw",
				name: "修改新闻",
				component: updatexw,
				meta: {
					requireAuth: true
				},

			},
			{
				path: '/listxw',
				name: '新闻列表',
				component: listxw,
				meta: {
					requireAuth: true
				},

			},
			{
				path: '/person',
				name: '个人信息',
				component: person,
				meta: {
					requireAuth: true
				},

			},
			{
				path: '/record',
				name: '交易记录',
				component: record,
				meta: {
					requireAuth: true
				},

			}
		],
	},

富文本编辑器

效果展示
下面几个名字是使用了富文本编辑器的回显

首先需要安装Vue-Quill-Editor
命令:npm install vue-quill-editor --save
下载quill(Vue-Quill-Editor需要依赖)
npm install quill --save

完整代码

<template>
	<div>
		<el-form ref="loginFormRef" label-width="100px" style="width: 60%" :model="loginForm">
			<el-form-item label="新闻标题">
				<el-input v-model="loginForm.title"></el-input>
			</el-form-item>
			<el-form-item label="新闻摘要">
				<el-input v-model="loginForm.newsabstract"></el-input>
			</el-form-item>
			<el-form-item label="新闻内容">
				<div class="edit_container" style="width: 100%">
					<quill-editor v-model="loginForm.text" ref="myQuillEditor" :options="editorOption"
						@blur="onEditorBlur($event)" @focus="onEditorFocus($event)" @change="onEditorChange($event)">
					</quill-editor>
				</div>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" @click="changePwd()">添加新闻</el-button>
			</el-form-item>
		</el-form>
		<div v-html="str" class="ql-editor">
			{{str}}
		</div>
	</div>

</template>

<script>
	import {
		quillEditor
	} from "vue-quill-editor"; //调用编辑器
	import 'quill/dist/quill.core.css';
	import 'quill/dist/quill.snow.css';
	import 'quill/dist/quill.bubble.css';

	export default {
		components: {
			quillEditor
		},

		data() {
			return {

				loginForm: {
					title: "",
					newsabstract: "",
					text: "",
					releasedate: "",

				},
				str: '',
			};
		},

		methods: {
			changePwd: function() {
				this.$refs.loginFormRef.validate(async valid => {
					if (!valid) return;
					const {
						data: res
					} = await this.axios.put("http://localhost:8088/news", this.loginForm)
					if (res) {

						this.$message.success("添加新闻成功")
						this.$router.push({
							path: "/listxw"
						});
					} else {
						this.$message.error("添加新闻失败")
					}
				})
			},
			onEditorReady(editor) { // 准备编辑器

			},
			onEditorBlur() {}, // 失去焦点事件
			onEditorFocus() {}, // 获得焦点事件
			onEditorChange() {}, // 内容改变事件
			// 转码
			escapeStringHTML(str) {
				str = str.replace(/&lt;/g, '<');
				str = str.replace(/&gt;/g, '>');
				return str;
			}

		},
		computed: {
			editor() {
				return this.$refs.myQuillEditor.quill;
			},
		},
		mounted() {
			let content = '<ul><li><strong>李佳豪</strong></li><li><strong><u>陈刚</u></strong></li><li><strong><s><u>李金铭</u></s></strong></li><li><em>杨军</em></li></ul>'; // 请求后台返回的内容字符串
			this.str = this.escapeStringHTML(content);
		}

	};
</script>

<style>
</style>

vue中富文本编辑器使用参考链接

本地源代码
前端E:\VNC\project\capital_vue
后端E:\VNC\project\capital

到此这篇关于vue中的ElementUI的使用详解的文章就介绍到这了,更多相关vue ElementUI 使用内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • Vue+ElementUI之Tree的使用方法

    Vue+ElementUI之Tree的使用,供大家参考,具体内容如下 前端代码 <template> <div> <el-dialog title="终端通讯录" :visible.sync="isOpen" class="el-dialog-mini"> <div class="forms-menu-con"> <!-- check-on-click-node:设置是否在

  • Vue+ElementUI使用vue-pdf实现预览功能

    Vue + ElementUI项目中使用vue-pdf实现简单预览,供大家参考,具体内容如下 1.安装 vue-pdf npm install --save vue-pdf 2.在vue页面中导入对应的组件 我这是通过点击 预览 按钮 获取id打开一个dialog来实现 <!--PDF 预览--> <el-dialog :title="PDF 预览" :visible.sync="viewVisible" width="80%"

  • vue+elementUi图片上传组件使用详解

    上传组件封装需求分析 在基于elementUI库做的商城后台管理中,需求最大的是商品管理表单这块,因为需要录入各种各样的商品图片信息.加上后台要求要传递小于2M的图片,因此封装了一个upload.vue组件作为上传页面的子组件,它用于管理图片上传逻辑. upload.vue解析 upload主要用于实现表单上传图片的需求,主要由input +img 构成当没有图片的时候显示默认图片,有图片则显示上传图片,因为input样式不太符合需求所以只是将起设置为不可见,不能将其设置为display:non

  • 解决vue elementUI 使用el-select 时 change事件的触发问题

    如下所示: <el-select v-model="level" size="mini" placeholder="请选择" :change="selectChange()"> <el-option v-for="item in select" :key="item.value" :label="item.label" :value="it

  • Vue中ElementUI分页组件Pagination的使用方法

    Vue中ElementUI分页组件Pagination的使用,供大家参考,具体内容如下 一.概要 ElementUI 提供了 el-pagination 组件,只要配置相应得参数和事件,即可实现分页. 二.实现 1.基本用法 <div class="pagination"> <el-pagination background layout="total, sizes, prev, pager, next, jumper" :current-page

  • vue使用ElementUI时导航栏默认展开功能的实现

    本文主要参考: http://element.eleme.io/#/zh-CN/component/menu 在使用elementUI的时候发现,能够展开的导航栏是不能展开的,效果这里先不演示了.可以在上边的网站上看到. 现在有这样的需求,就是说,默认的时候需要展开这些导航,就是一打开界面的时候就能够显示导航里面的菜单内容. 具体操作是这样的: <script src="//unpkg.com/vue/dist/vue.js"></script> <scr

  • Vue中使用ElementUI使用第三方图标库iconfont的示例

    1.在http://www.iconfont.cn/阿里巴巴图标库添加图标到自己项目中,然后点击更多项目中的编辑项目 2.修改前缀为el-icon-xxx,xxx自定义,然后将项目下载自本地 3.将这5个文件放入到项目文件中,将iconfont.css引入到Vue项目中, 然后修改iconfont.css的.iconfont处,将其修改为下图所示 4.修改iconfont.css后,大致如下图所示 5.最后就可以采用icon相同方式引入图标,如下图方式引用即可 注意:如果修改前缀为el-icon

  • vue中的ElementUI的使用详解

    登录+sessionStorage 效果展示 登录成功后会把用户id存入前端的sessionStorage,拦截器会根据是否存在用户id来进行拦截 也可以将用户权限存入sessionStorage,然后当访问某个页面的时候在created方法中判断是否具有权限 <template> <div class="login-wrap"> <el-form class="login-container" ref="loginFormR

  • vue中使用codemirror的实例详解

    这篇文章在vue里使用codemirror遇到的问题,写的很不错,还有下载的方法,大家可以点击查看. 以下是自己使用过的,做出来的例子: 做出来的效果图: 记住使用之前要npm下载哦 npm install vue-codemirror --save main.js import { codemirror } from 'vue-codemirror' import 'codemirror/lib/codemirror.css' Vue.use(VueCodemirror) 再到组件中使用 im

  • vue中引入mxGraph的步骤详解

    第一步:下载npm包 npm install mxgraph --save 第二步:新建一个index.js文件 文件内容如下 import mx from 'mxgraph'; const mxgraph = mx({ mxImageBasePath: './src/images', mxBasePath: './src' }); // decode bug https://github.com/jgraph/mxgraph/issues/49 window.mxGraph = mxgraph

  • vue中的过滤器实例代码详解

    过滤器 1.过滤器规则 Vue.js 允许你自定义过滤器,可被用于一些常见的文本格式化.过滤器可以用在两个地方: 双花括号插值{{}}和  v-bind 表达式 (后者从 2.1.0+ 开始支持).过滤器应该被添加在 JavaScript 表达式的尾部,由"管道"符号指示: <!-- 在双花括号中 --> {{ name | Upper }} <!-- 在 `v-bind` 中 --> <div v-bind:id="martin | Upper

  • Vue中使用vux配置代码详解

    一.根据vux文档直接安装,无需手动配置 npm install vue-cli -g // 如果还没安装 vue init airyland/vux2 my-project // 创建名为 my-project 的模板 cd my-project // 进入项目 npm install --registry=https://registry.npm.taobao.org // 开始安装 npm run dev // 运行项目 二.想在已创建的Vue工程里引入vux组件 <1>. 在项目里安装

  • 在vue 中使用 less的教程详解

    1.安装 npm install --save-dev less less-loader npm install --save-dev style-loader css-loader 先在index.html页面head标签内插入这段代码 <script> (function (doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? 'orientationchange'

  • 发布订阅模式在vue中的实际运用实例详解

    订阅发布模式定义了一种一对多的依赖关系,让多个订阅者对象同时监听某一个主题对象.这个主题对象在自身状态变化时,会通知所有订阅者对象,使它们能够自动更新自己的状态. 比如addEventListener 这个api就是个发布订阅模式 如果用过vue的同学,可以把他类比于 watch 下面我们看一个例子 var observe={ fnsObj:{}, // 订阅方法 on:function(key,fn){ if(!observe.fnsObj[key]){ observe.fnsObj[key]

  • 基于Vue中使用节流Lodash throttle详解

    在Vue中使用 Lodash.throttle 来做节流 在Vue中,有时需要对ajax请求提交进行节流操作.这时候,如果页面在请求成功之后会跳转,使用vue指令once或者加载一个loading遮罩禁止点击即可,但如果请求之后不跳转,并且loading不适用时,需要通过其他方式来实现节流,比如通过标识位判断等,这里我们着重说一下如何通过lodash.throttle来实现节流 lodash lodash是一个广受欢迎的js工具库,其中包含了各种各样的工具函数,方便开发时不需要反复造轮子,更关注

  • 封装一下vue中的axios示例代码详解

    在vue项目中,和后台交互获取数据这块,我们通常使用的是axios库,它是基于promise的http库,可运行在浏览器端和node.js中.他有很多优秀的特性,例如拦截请求和响应.取消请求.转换json.客户端防御cSRF等.所以我们的尤大大也是果断放弃了对其官方库vue-resource的维护,直接推荐我们使用axios库.如果还对axios不了解的,可以移步axios文档. 安装 npm install axios; // 安装axios 好了,下面开始今天的正文. 此次封装用以解决: (

  • Vue 中使用 typescript的方法详解

    什么是typescript typescript 为 javaScript的超集,这意味着它支持所有都JavaScript都语法.它很像JavaScript都强类型版本,除此之外,它还有一些扩展的语法,如interface/module等. typescript 在编译期会去掉类型和特有语法,生成纯粹的JavaScript. Typescript 5年内的热度随时间变化的趋势,整体呈现一个上升的趋势.也说明ts越来越️受大家的关注了. 安装typescript npm install -g ty

随机推荐