@[TOC]小益回收

Vue报错

vue-router.esm.js?8c4f:2089 Uncaught (in promise) NavigationDuplicated {_name: “NavigationDuplicated”, name: “NavigationDuplicated”, message: “Navigating to current location (”/Orderfinish") is not allowed", stack: “Error↵ at new NavigationDuplicated (webpack-int…node_modules/vue/dist/vue.runtime.esm.js:2178:14)”}
大致意思就是不允许使用this.$router.push
解决方法
1. 安装最新的router
npm i vue-router@3.0 -S
2.在 main.js里添加一段代码。

代码如下:

import Router from ‘vue-router’
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {return routerPush.call(this, location).catch(error=> error)
}

如何使用php给前端返回数据 且保证json格式

<?php
header('Content-Type:application/json');  //此声明非常重要
/*链接数据库 */
$pdo = new PDO('mysql:host=localhost;dbname=xiaoyi', 'root', '');try {/*query 执行的是select语句,返回值是PDOStatement对象*/$result=$pdo->query("select * from orderList")->fetchAll(PDO::FETCH_ASSOC);if(count($result)>0){echo json_encode($result);}else{echo '当前没有订单';}$db = null; //关闭数据库} catch (PDOException $e) {die("数据库连接失败".$e->getMessage());
}

加上这句代码即可!!一定要记住

php接口返回数据 用echo 还是return?

return 作为函数返回值或结束语句,是返回的数据的指针,也就是数据存放的地址,而接口需要返回的是真实的数据
在tp框架中,return关键字的确是可以给返回数据的,也就是可以作为接口返回数据关键字的,但是用原生的php是不行的,这应该是tp框架内部做过处理了吧!

js判断数组是否为空 以及 是否含有某个值

1.arr.length判断
2. arr.indexOf( ) 找不到返回-1
for循环
arr.find(val=>{ if (val ===2) { console.log(‘有2’)}})
arr.includes 返回结果为布尔类型

最后项目还是选择以thinkphp写接口

vue实现上传头像和预览头像

<template><div><div class="header"><router-link tag="i" to="/my" class="iconfont  icon-fanhui1"></router-link><span class="title">个人档案</span><div class="photo" ><img class="photo-area" @click="selecttouxiang"  :src="src"><i class="iconfont icon-tubiaosvg-"></i></div></div><input type="file" ref="file" hidden @change="fileChange"><div class="infos"><div class="item" @click="showUpdateName"><span class="username">昵称</span><span>{{username}}<i class="iconfont icon-fanhui"></i></span></div><div class="item"><span class="username">邮箱</span><span>{{email}}<i class="iconfont icon-fanhui"></i></span></div><div class="item"><span class="username">密码</span><span>...<i class="iconfont icon-fanhui"></i></span></div><!--修改昵称--><mt-popupv-model="popupVisible"position="bottom"><div style="display: flex;justify-content: space-between;color: #0a6999;"><span @click="popupVisible=false" >取消</span><span style="color: black ">昵称</span><span @click="updateName">确定</span></div><div class="textarea"><van-fieldv-model="newName"rows="1"autosizetype="textarea"maxlength="20"placeholder="请输入昵称"show-word-limit></van-field></div></mt-popup><!--/修改昵称--></div><!--预览头像--><van-image-preview class="imgPreview" v-model="isShow" :images="images"><van-nav-barslot="cover"left-text="取消"right-text="确定"left-arrow@click-left="isShow=false"@click-right="onClickRight"></van-nav-bar></van-image-preview><!--/预览头像--></div>
</template>><script>import { Toast } from 'mint-ui'export default {name: "PersonMaterial",data(){return{isShow: false,popupVisible: false,newName: '',src: '',username: '',email: '',images: []}},methods: {showUpdateName(){this.popupVisible=true},updateName(){},/*input 默认不显示 点击图片触发input 为file的点击*/selecttouxiang() {this.$refs.file.click()},/*input 输入框发生改变自动触发事件*/fileChange() {//1.获取file 类型的input 选择的文件对象// console.log(this.$refs.file)const fileObj = this.$refs.file.files[0]//2. 使用window.URL.createObjectURL(fileObj)// const fileData=window.URL.createObjectURL(fileObj)/*本来没有确认取消 自定义模板类容 要用插槽*///图片转化成base64格式var reader = new FileReader()reader.onload = (fileObj) => {let res = fileObj.targetthis.src = res.resultthis.images = [this.src]}reader.readAsDataURL(fileObj)this.isShow=true},onClickRight() {const fd = new FormDatafd.append('photo', this.images[0])//将图片路径存进数据库里面this.$axios.post('/api/Order/upDatePhoto.html', fd).then(res => {if (res.data.code > 0) {Toast('更新成功')this.src = this.images[0]} else {Toast('更新失败')}this.isShow = false}).catch(function (err) {console.log(err)})},},/*获取当前页面的用户信息*/mounted () {this.$axios.get('/api/Order/selectPhoto.html').then(res=> {console.log(res.data)if(res.data.code>0) {this.username=res.data.data.usernamethis.email=res.data.data.emailthis.src=res.data.data.photo}}).catch(function (err) {console.log(err)})}}
</script><style lang="stylus" scoped>.textarea >>> .van-field__word-limitwidth 10%float right.imgPreview >>> .van-image__imgwidth 100%height 100%margin-top 150px.imgPreview >>> .van-nav-bar__left  .van-nav-bar__textposition absoluteleft 10pxbottom 10pxcolor #ffffont-size 15px.imgPreview >>> .van-nav-bar__right  .van-nav-bar__textposition absoluteright 10pxbottom 10pxcolor #ffffont-size 15px.imgPreview >>>.van-image-preview__indexmargin-top 20pxtext-align centercolor #fffdiv.mint-popup.mint-popup-bottomwidth 100%
.headerheight 4rembackground-color #37D164text-align centercolor #fff.imgPreviewbackground-color blackposition absolutetop 0bottom 0left 0right 0width 100%.titledisplay: block;padding-top .4remfont-size .4rem.icon-fanhui1font-size: .45rem;position absolutetop .4remleft .4rem.photo-areawidth 2remheight 2remborder-radius 50%z-index 999margin .4rem auto.icon-tubiaosvg-font-size: .5rem;position: absolute;top: 2.5rem;right: 2.8rem;border-radius: 50%;background: #18323b78;.itemheight: .8rem;line-height: .8rem;display flexjustify-content space-aroundfont-size .35remborder-bottom .01rem solid #cacaca.usernamewidth: 65%;.icon-fanhuipadding-left: .2rem;.updatePasswordwidth 75%
</style>

图示:

!!!注意 图片转成base64之后数据库的类型必须存为longtext不然不够长 图片显示不出来

给按钮绑定点击事件不生效

再移动端项目中 如果使用了betterscroll默认会阻止touch行为

       mounted () {this.scroll=new BScroll(this.$refs.wrapper,{ click: true})},

此时点击按钮就生效了!

thinkphp实现搜索功能

public function useradmin(){判断关键字是否存在$keywords=input('keywords');if($keywords){$map['username|email'] = array('like','%'.$keywords .'%');$users =Db::name('tb_user')->where($map )->select();$this->assign('users',$users);return $this->fetch();}else{$users=Db::name('tb_user')->paginate(5);$this->assign('users',$users);return $this->fetch();}}

这个搜索是将关键字通过form表单传到后台进行判断 在和数据库中的某个字段进行比较返回给前端

<div class="layui-body"><!-- 内容主体区域 --><div style="padding: 15px;"><form method="post" action="{:url('xiaoyi/userAdmin')}"><div class="demoTable">搜索关键字:<div class="layui-inline"><input class="layui-input" id="search"  name="keywords" autocomplete="off"></div><button type="submit" class="layui-btn" data-type="reload">搜索</button></div></form><table class="layui-table"><thead><tr><th>ID</th><th>姓名</th><th>密码</th><th>邮箱</th><th>操作</th></tr></thead><tbody><ul>{volist id="v" name="users"}<tr><td>{$v.id}</td><td >{$v.username}</td><td>{$v.password}</td><td>{$v.email}</td><td><a href="{:url('xiaoyi/useredit',['id'=>$v.id])}" class="layui-btn layui-btn-xs">编辑</a><button   onclick="showdel('{$v.id}','{$v.username}')" class="layui-btn layui-btn-danger layui-btn-xs">删除</button></td></tr>{/volist}</ul></tbody></table></div>
</div>

图片上传

如果图片如果不传base64,而是直接用form上传文件的话,一定要设置这个属性:enctype=“multipart/form-data”
思路大概是 一个type='file’的input输入框 默认不显示,点击一个东西触发input的点击 弹出选择文件

 function  fileChange() {//1.获取file 类型的input 选择的文件对象const fileObj =   document.getElementById('input').files[0]var reader = new FileReader()reader.onload = (fileObj) => {let res = fileObj.targetdocument.getElementById('img').src= res.result  //实现预览document.getElementById('photo').value=res.result //将base64格式的数据传给一个默认不显示的输入框用表单提交给后台}reader.readAsDataURL(fileObj)}
  <form method="post" action="{:url('product/addProduct')}" enctype="multipart/form-data"><input id="input"  onchange="fileChange()" type="file"  style="display: none"><input type="hidden" id="photo" name="photo" value=""><div class="product">商品图片<i onclick="addImg()" id="icon" style="font-size:60px ;color: grey" class="iconfont icon-web-icon-"></i>//点击图标触发文件选择显示<img class="img" id="img"></div></div></form>

swiper组件轮播的时候如果写相对路径 必须
require不能省

        <img class="swiper-img"  :src="item.imgUrl">swiperList: [{id: 1, imgUrl:  require('../../../assets/img/w.png')},{id: 2, imgUrl: require('../../../assets/img/s.png')}]

Vue 自提项目 --小益回收 遇到的问题(二)相关推荐

  1. Vue 自提项目 --小益回收 遇到的问题(一)

    1.vue设置背景图片 如果直接给一个元素添加类 定义他的背景图片,编译打包后,配置到服务器上时,由于路径解析的问题,图片并不能够正确的显示出来,如下CSS样式: background:url(&qu ...

  2. H5盲盒商城网站源码开发小程序抽奖系统商城搭建 VUE+PHP后台项目

    这是H5盲盒商城网站源码开发小程序抽奖系统商城搭建 VUE+PHP后台项目(代码不加密,开源) 1.带推广二维码功能 2.含充值3级分销功能 3.盲盒回收成余/额功能 等功能 可以个性化定制开发等 源 ...

  3. Github项目分享——Vue随机刷装备小游戏

    Vue随机刷装备小游戏 项目地址 https://github.com/Couy69/vue-idle-game 游戏设计 通过副本获得装备与金币 装备分为四个等级:破旧.普通.神器.史诗 主角默认每 ...

  4. node.js+Vue计算机毕设项目勤工俭学管理小程序(程序+LW+部署)

    该项目含有源码.文档.程序.数据库.配套开发软件.软件安装教程.欢迎交流 项目运行 环境配置: Node.js+ Vscode + Mysql5.7 + HBuilderX+Navicat11+Vue ...

  5. [vue移动端项目] 严选商城项目 使用vue+vant做的移动端商城小项目

    文章目录 项目准备 安装 amfe-flexible 安装 第三方插件 postcss-pxtorem 配置vue.config.js reset.css 重置样式表 安装less 预编译语言 安装v ...

  6. vue.js 构建项目_使用Vue.js和AWS Amplify构建Chatbot

    vue.js 构建项目 Over the last few years, chatbots have exploded in popularity. It makes sense that busin ...

  7. Vue + Spring Boot 项目实战(十五):动态加载后台菜单

    重要链接: 「系列文章目录」 「项目源码(GitHub)」 本篇目录 前言 一.后端实现 1.表设计 2.pojo 3.菜单查询接口(树结构查询) 二.前端实现 1.后台页面设计 2.数据处理 3.添 ...

  8. 前端面试题(HTML、JS、Vue、React、小程序)

    前端面试题 HTML && CSS HTML 1.Div 里面有个一个div ***** Q:有几种方法可以水平,垂直居中 2.doctype的作用 * 3.link标签和import ...

  9. 国外多语言盲盒商城网站源码开发搭建 VUE+PHP后台项目

    这是H5盲盒商城网站源码开发小程序抽奖系统商城搭建 VUE+PHP后台项目(代码不加密,开源) 1.带推广二维码功能 2.含充值3级分销功能 3.盲盒回收成余/额功能 等功能 可以个性化定制中文,英文 ...

最新文章

  1. leetcode算法题--球会落何处
  2. 单片机 10种软件滤波方法的示例程序
  3. C语言实现组织图kohone/topology算法(附完整源码)
  4. Codevs 1689 建造高塔
  5. Python DearPyGui 多线程与异步
  6. RHCS双机集群调测
  7. 直播评论发弹幕切图功能点集合
  8. Python编程 | 随机生成车牌号
  9. DB9引脚在UART,CAN,RS485中的定义
  10. 桌面支持--Auto Cad 2012安装方法
  11. Requested setting DATABASES, but settings are not configured. You must either define the environment
  12. 快过年了,用五种不同的JS特效带你看烟花(包邮送元宇宙图书)
  13. 图像标注工具python+opencv
  14. 怎样看笔记本上有无无线网卡?
  15. 棕榈油跌停见顶,铁矿石认沽上涨,YP05惊天大反弹2022.3.14
  16. Qt实现在QLabel上显示图片并进行线条/矩形框/多边形的绘制
  17. 理解类8583报文协议
  18. 尚硅谷maven视频教程笔记
  19. python中的_和__
  20. 【MATLAB实验】MATLAB图形绘制相关函数与定积分计算

热门文章

  1. Android屏幕截图,View截图(干货)
  2. wallpaper代码_五行Python代码自动换你的电脑桌面壁纸(内附源码和exe)
  3. 黑客入门指南,小白如何成长为一名黑客之基本功
  4. android 缓冲条,荣耀 Note10 体验:6.95 英寸的「平板级」大屏之外,还有全面旗舰的体验...
  5. 每天都有人偷我森林的能量,我写了一个蚂蚁森林自动化收取能量!看你们咋偷!
  6. Linux系统中的文件传输优化
  7. Educoder头歌数据结构顺序表及其应用
  8. VR全景餐厅提高顾客用餐体验促进餐厅宣传
  9. 新手学习计算机,做基础软件开发者
  10. 六、Scala从入门到精通一一面对对象编程(初级)