vue 仿写微信公众号自定义菜单
时间:2019-09-18
本文章向大家介绍vue 仿写微信公众号自定义菜单,主要包括vue 仿写微信公众号自定义菜单使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
先看效果图
代码参考
<template> <div> <!-- 公众号设置 --> <el-col :span="24" style=" margin-top: 10px;"> <h2 style="font-weight: 300; margin-left: 20px; font-size: 22px;">公众号设置</h2> <!-- <el-col :span="12" :offset="6"> <div class="grid-content bg-purple warning"> <p> <i class="el-icon-warning tips"></i>温馨提示: <span class="on">立即授权</span> </p> <p>微信公众号提现需要特约商户签约,材料交给我们代为提交。签约费用500元</p> </div> </el-col> --> <el-col :span="24" style=" margin-top: 30px;"> <el-col :span="5" class="left"> <img class="top" :src="top" /> <img class="bottom" :src="bottom" /> <div style="background: #F4F5F9; min-height: 438px; position: absolute; top: 63px; width: 320px; "> </div> <div class="textbot"> <div class="li" v-for="(item,indx) in list" :key="indx" > <div v-if="activeClass == indx"> <div class="add" @click="add(indx)"><i class="el-icon-plus"></i></div> <div class="tianjia"> <div class="addadd" v-for="(item,index) in item.list" :key="index" :class="addindex == index ? 'active':''" @click="gettem(item,index)">{{item.name}}</div> </div> </div> <div class="text" :class="activeClass == indx ? 'active':''" @click="getItem(item,indx)">{{item.name}}</div> </div> <div class="li" v-if="list.length < 3"> <div class="text" @click="addtext"><i class="el-icon-plus"></i></div> </div> </div> </el-col> <el-col :span="15" style=" padding-left: 20px;"> <el-card class="box-card right"> <div slot="header" class="clearfix"> <span>{{input}}</span> <el-button style="float: right; padding: 3px 0" type="text" @click="delet">删除子菜单</el-button> </div> <div style="display: flex;"> <label style="line-height: 34px; width:80px;">菜单名称</label> <el-input v-model="input" placeholder="请输入内容" style="width:70%;" ></el-input> </div> <p style="color: #9A8D8D;margin-left: 80px;">仅支持中英文和数字,字数不超过4个汉字或8个字母</p> <div style="display: flex;"> <label style="line-height: 34px; width:80px;">菜单内容</label> <el-radio-group v-model="radio" style="line-height: 45px;"> <el-radio :label="1">平台模板</el-radio> <el-radio :label="2">跳转的网页</el-radio> </el-radio-group> </div> <div style="background: #fff;padding:10px 0;" v-if="radio == 1"> <el-radio-group v-model="radiobottom" style="padding:0 30px;"> <p style="margin: 8px 0;" v-for="(item,index) in listlist" :key="index"> <el-radio :label="index">{{item.name}}{{item.http}}</el-radio> </p> </el-radio-group> </div> <div style="background: #fff;padding:10px 0;" v-if="radio == 2"> <p style="color: #9A8D8D;margin-left: 30px;">订阅者点击该子菜单会跳到以下链接</p> <div style="display: flex; padding:0 30px;"> <label style="line-height: 34px; width:65px;">页面地址</label> <el-input v-model="inputhttp" placeholder="请输入内容" style="width:70%;"></el-input> </div> </div> </el-card> </el-col> <el-col :span="24"> <el-button type="primary" style="display: block;margin: 10px auto;">保存并发布</el-button> </el-col> </el-col> </el-col> </div> </template> <script> export default { data () { return { top: '../static/img/top.png', bottom: '../static/img/bottom.png', activeClass: 0, addindex: -1, input: '', inputhttp: '', radio: 1, radiobottom: 0, shu: 6, id: 1, list: [ { name: '菜单一', http: 'http://localhost:8001', id: 1, list: [{ 'name': '我是1', http: 'http://localhost:8011', id: 4 }] }, { name: '菜单二', http: 'http://localhost:8002', id: 2, list: [{ 'name': '我是2', http: 'http://localhost:8021', id: 5 }] }, { name: '菜单三', http: 'http://localhost:8003', id: 3, list: [{ 'name': '我是3', http: 'http://localhost:8031', id: 6 }] } ], listlist: [] } }, mounted () { this.rech() this.input = this.list[0].name this.inputhttp = this.list[0].http }, watch: { // 如果 `input` 发生改变,这个函数就会运行 input: function () { for (var i = 0; i < this.list.length; i++) { for (var j = 0; j < this.list[i].list.length; j++) { if (this.list[i].list[j].id === this.id) { this.list[i].list[j].name = this.input } } if (this.list[i].id === this.id) { this.list[i].name = this.input } } this.rech() // 限制名字个数 var temp = 0 for (var k = 0; k < this.input.length; k++) { if (/[\u4e00-\u9fa5]/.test(this.input[k])) { temp += 2 } else { temp++ } if (temp > 8) { this.input = this.input.substr(0, k) } } }, inputhttp: function () { for (var i = 0; i < this.list.length; i++) { for (var j = 0; j < this.list[i].list.length; j++) { if (this.list[i].list[j].id === this.id) { this.list[i].list[j].http = this.inputhttp } } if (this.list[i].id === this.id) { this.list[i].http = this.inputhttp } } this.rech() } }, methods: { // 父元素 getItem (item, index) { this.addindex = -1 this.activeClass = index // 把当前点击元素的index,赋值给activeClass this.input = item.name this.inputhttp = item.http this.id = item.id this.rech() }, // 子元素 gettem (item, index) { this.addindex = index console.log(item) this.input = item.name this.inputhttp = item.http this.id = item.id this.rech() }, // 增加 add (index) { this.shu++ this.list[index].list.push({ 'name': '子菜单', http: 'http://localhost:8000', id: this.shu }) this.rech() }, addtext () { this.shu++ this.list.push({ 'name': '菜单', http: 'http://localhost:8000', id: this.shu, list: [] }) this.rech() }, // 删除 delet () { this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { for (var i = 0; i < this.list.length; i++) { for (var j = 0; j < this.list[i].list.length; j++) { if (this.list[i].list[j].id === this.id) { this.list[i].list.splice(j, 1) this.addindex = -1 this.rech() this.$message({ type: 'success', message: '删除成功!' }) } } if (this.list[i].id === this.id) { this.list.splice(i, 1) this.activeClass = -1 this.rech() this.$message({ type: 'success', message: '删除成功!' }) } } }).catch(() => { this.$message({ type: 'info', message: '已取消删除' }) }) }, rech () { this.listlist = [] this.list.forEach(item => { this.listlist.push({ name: item.name, http: item.http }) item.list.forEach(item => { this.listlist.push({ name: item.name, http: item.http }) }) }) for (var i = 0; i < this.listlist.length; i++) { if (this.listlist[i].name === this.input) { this.radiobottom = i } } } } } </script> <style lang="scss" scoped> .warning { border: 1px solid #91d5ff; background-color: #e6f7ff; padding: 5px 20px; } .on { text-align: right; float: right; color: #1890ff; } .tips { color: #1890ff; font-size: 20px; margin-right: 10px; } .left { min-width: 390px; min-height: 550px; position: relative; padding-left: 40px; } .top { position: absolute; top: 0px; } .bottom { position: absolute; bottom: 0px; } .textbot { position: absolute; bottom: 0px; left: 82px; width: 100%; } .active { border: 1px solid #44B549 !important; color: #44B549 !important; } .li { float: left; width: 93px; line-height: 48px; border: 1px solid #E7E7EB; background: #FAFAFA; text-align: center; cursor: pointer; color: #999; position: relative; } .text{ height: 50px; } .text:hover { color: #000; } .add { position: absolute; bottom: 60px; width: 100%; line-height: 48px; border: 1px solid #E7E7EB; background: #FAFAFA; } .tianjia { position: absolute; bottom: 110px; width: 100%; line-height: 48px; background: #FAFAFA; } .addadd { width: 100%; line-height: 48px; border: 1px solid #E7E7EB; background: #FAFAFA; height: 48px; } .right { background: #F4F5F9; min-height: 550px; } </style>
原文地址:https://www.cnblogs.com/1212dsa/p/11543351.html
- 碎片化 | 第四阶段-43-struts2拦截器interceptor-视频
- Spring Cloud Edgware新特性之二:如何配置Zuul的Hystrix线程池
- 碎片化 | 第四阶段-44-struts2注解使用-视频
- Spring Cloud Edgware新特性之:解决Eureka中Jersey 1.x版本过旧的问题-不使用Jersey
- 如何自定义微服务的Instance ID
- 怎样做情感分析
- Python|编写自己的类
- 碎片化 | 第四阶段-45-session为空问题解决-视频
- 以后有机会写框架用得着的
- 合并两个不相关的Git仓库
- 用 Tensorflow 建立 CNN
- 碎片化 | 第四阶段-36-struts-spring结合jdbc实现删除功能-视频
- 跨域访问支持(Spring Boot、Nginx、浏览器)
- 自己动手写个聊天机器人吧
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Android 7.0开发获取存储设备信息的方法
- Android中默认系统的声音/大小修改和配置详解
- Android开发中计算器的sin、cos及tan值计算问题分析
- Android开发实现绘制淘宝收益图折线效果示例
- Android自定义View实现搜索框(SearchView)功能
- android 监听SD卡文件变化的实现代码
- Android监听手机短信的示例代码
- Android开发之图片压缩工具类完整实例
- Android6.0开发中屏幕旋转原理与流程分析
- Android中WebView的基本配置与填坑记录大全
- Android开发实现ListView异步加载数据的方法详解
- Android开发实现AlertDialog中View的控件设置监听功能分析
- 详解Android 语音播报实现方案(无SDK)
- Android实现中轴旋转特效 Android制作别样的图片浏览器
- Android使用DrawerLayout实现双向侧滑菜单