最近正在用Vue做一个电商项目。利用工作前后空隙时间。


1.promise的使用

点这里 如何在实际项目中使用Promise

2. Express Route 前后端传参的两种方法

(1)req.params

服务端代码如下:

const express = require('express')
const router = express.Router() router.get('/:name', function (req, res) {
res.send('hello, ' + req.params.name)
}) module.exports = router

前端访问地址 http://localhost:3000/testRoute/testParams

req.params.name 即为testParams

(2)req.query

服务端代码如下:

router.get('/', function(req, res, next) {
var res = res
var req = req
var sql = "select parent_id, cat_name, cat_logo, level from syscategory_cat WHERE parent_id=" + req.query.testKey
connection.query(sql, function(err, rows, fields) {
res.send(rows)
})
})

前端代码如下:

getCategory() {
this.$ajax.get('http://localhost:3000/category/', {
params: {
testKey: testValue
}
}).then((res) => {
resolve(res)
}).catch(function (error) {
reject(error)
})
}

此处发送的参数 testKey, 即为req.query.testKey

另附两篇express相关入门文章:

1.使用express搭建web环境

2.express基本用法

3.商品评论打星星评分功能

  思路:

  1. 把六种分数的星星拼成一张雪碧图
  2. 点击星星的时候,获取鼠标的位置
  3. 根据位置来更改background-position的值来显示不同的星星改变分数。

雪碧图如下:

css代码如下:

.star.big {
line-height: 20px;
vertical-align: -4px;
width: 181px;
height: 20px;
background: url(../member/star_b.png) no-repeat 0 -100px;
}
.star.s_5 {
background-position: 0 0;
}
.star.s_4 {
background-position: 0 -20px;
}
.star.s_3 {
background-position: 0 -40px;
}
.star.s_2 {
background-position: 0 -60px;
}
.star.s_1 {
background-position: 0 -80px;
}

js代码如下:

$('.star').on('click',function(event){
var x = event.offsetX;
if(x<21){
this.className = 'star big s_1';
$(this).next().val(1);
return;
}
if(x > 40 && x < 61){
this.className = 'star big s_2';
$(this).next().val(2);
return;
}
if(x > 80 && x < 101){
this.className = 'star big s_3';
$(this).next().val(3);
return;
}
if(x > 120 && x < 141){
this.className = 'star big s_4';
$(this).next().val(4);
return;
}
if(x > 160 && x < 181){
this.className = 'star big s_5';
$(this).next().val(5);
return;
}
});

4.商品浏览历史

思路:使用store.js,在商品详情页设置Local Storage数据,在需要调用的地方获取Local Storage数据。

set设置数据页面代码:

browserStore.set(key, value);

get获取数据页面代码:

browserStore.get(key, function(rs) {
rs = JSON.decode(rs);
});

5.express服务启动命令

set DEBUG=server:* & npm start

启动成功截图:

每日技术总结:promise,express route,评分,local storage商品浏览历史,的更多相关文章

  1. ARM模式下创建Express Route

    在Azure的ARM模式下,创建Express Route的命令和ASM模式下是有一些区别的. 本文将介绍在ARM模式下,如果创建Express Route的Circuit. 1. 查看支持的Serv ...

  2. 如何在ARM中创建Express Route

    很早之前就想试试Azure的express route,但是一直没有找到合适的机会,正好有个客户需要上express route,所以最近先自己研究研究,防止在做poc的时候耗费更多时间,本次场景我们 ...

  3. nodejs express route 的用法

    express 中文社区:http://expressjs.jser.us/community.html nodejs express route 的用法 1. 首先是最基本的用法. 1 2 3 4 ...

  4. 一根Express Route同时支持ARM和ASM的VNET

    ARM模式的Azure管理模式在China Azure上已经正式落地了.今后在China Azure上应该主要以ARM的模式创建VM了. 并且目前Express Route也已经可以在ARM模式下创建 ...

  5. Express Route的配置

    ExpressRoute在中国已经Preview了. 本篇文章讲介绍ExpressRoute如何配置. Express Route的逻辑拓扑结构: 在配置Express Route之前,需要做VLAN ...

  6. web页面缓存技术之Local Storage

    业务:检测页面文本框的值是否有改变,有的话存入缓存,并存储到数据库,这样用户异常操作后再用浏览器打开网页,就可避免重新填写数据 数据库表:Test,包含字段:PageName,PageValue BL ...

  7. 【JEECG技术博文】Local storage &amp; easyui extensions

    1. Local storage背景 cookie弊端:同域内http请求都会带cookie,添加带宽和流量:有个数和限制大小(约4K). 在HTML5中,本地存储是一个window的属性.包含loc ...

  8. Session,Cookie 和local storage的区别

    以前从没有听说过local storage, 在网上查了一些资料,得到如下结论 从存储位置看,分为服务器端存储和客户端存储两种 服务器端: session 浏览器端: cookie, localSto ...

  9. HTML5本地存储(Local Storage) 的前世今生

    长久以来本地存储能力一直是桌面应用区别于Web应用的一个主要优势.对于桌面应用(或者原生应用),操作系统一般都提供了一个抽象层用来帮助应用程序保存其本地数据 例如(用户配置信息或者运行时状态等). 常 ...

随机推荐

  1. a标签中的javascript:;是什么

    a标签中的javascript:;是什么 一.问题 <a>标签中href="javascript:;"表示什么意思?? <a id="jsPswEdit ...

  2. 如何让hudson的两个job共用一个svn工作目录

    作者:朱金灿 来源:http://blog.csdn.net/clever101 现在我的需求是这样的:一个软件需要编译完全版本和基础版本,完全版本的基础功能较多,基础版本只包含了基础功能.有时只需要 ...

  3. 分享js寄生组合模式继承

    function person(){ this.name = 'taobao'; this.showMess = function(){ return this.name; } } person.pr ...

  4. Shiro + SSM(框架) + Freemarker(jsp)

    Shiro + SSM(框架) + Freemarker(jsp)讲解的权限控制Demo,还不赶快去下载? 我们知道Ajax不能做页面redirect和forward跳转,所以Ajax请求假如没登录, ...

  5. Interrupt distribution scheme for a computer bus

    A method of handling processor to processor interrupt requests in a multiprocessing computer bus env ...

  6. Input/output subsystem having an integrated advanced programmable interrupt controller for use in a personal computer

    A computer system is described having one or more host processors, a host chipset and an input/outpu ...

  7. Android学习笔记进阶17之LinearGradient

    具体的看一下博文:Android学习笔记进阶15之Shader渲染 package xiaosi.BitmapShader; import android.app.Activity; import a ...

  8. golang beego cache

    package main import ( "fmt" "github.com/astaxie/beego/cache" "time" ) ...

  9. atxserver2安装与使用

    atxserver2的使用 1.首先clone atxserver2代码,此时使用pip3 install requirements后执行python main.py 会提示“ [WinError 1 ...

  10. 洛谷 P1610 鸿山洞的灯

    P1610 鸿山洞的灯 题目描述 已知n盏灯以及每盏灯的位置p[i],p[i]均不相等,两盏相邻的灯当小于dist时,若这个安全距离里面还有灯是亮着时,就可以关掉该盏灯,(即若第i-1盏与第i+1盏的 ...