【彩彩只能變身隊】后端工作總結

2018.06.09 早上8點到晚上10點 沖刺前后端交互(vue+express+mysql)

8:00-12:00 : 前端把請求寫好:

<template>

<div class="LoginForm">
<el-form ref="form" label-width="80px" action="api/info">
<!--<myCanvas></myCanvas>-->
<el-row>
<el-col :span="8"><div class="grid-content"></div></el-col>
<el-col :span="8">
<div class="grid-content login">
<p class="loginTitle">登錄 | Login</p>
<el-input type="text" v-model="userName" placeholder="請輸入你的用戶名"></el-input>
<el-input type="password" v-model="ori_password" placeholder="請輸入你的密碼"></el-input>
<el-button type="info" @click="login">登錄</el-button>
<el-button type="info" @click="dialogFormVisible = true">注冊</el-button>
<!--<el-button type="warning" @click="findPasswordVisible = true" style="float: right">找回密碼</el-button>-->
</div>
</el-col>
<el-col :span="8"><div class="grid-content"></div></el-col>
</el-row>
</el-form>
</div>

</template>

<script>
import store from '../store/index'
export default {
name: "LoginForm",
data() {
return {
userName: '',
ori_password: '',//原始未加密
}
},

methods: {
login() {
this.password = this.ori_password
this.$http.post('api/login', {
username: this.userName,
password: this.password}
).then((response) => {
this.loginResponse(response)
}, (response) => {
console.log(response)
}
)
},

loginResponse(response){
let body = response.data;
if(body.state === '登錄成功'){
this.$router.push('/home');}
//let userid = body.id;
//this.$store.dispatch('setUsername', {name: this.userName, id:userid, token:body.token});}
else this.$router.push('/');
}
}
}
</script>

12:00 - 17:00 后端開始進行交互來嘗試著接受前端的post請求:

一。首先配置好proxytable,來實現代理和跨域,這樣的話一個后端的路由就可以處理來自兩個url的請求了:

dev: {
env: require('./dev.env'),
host:'localhost',
port: 8080,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api/' : {
target:'http://localhost:3000/',
changeOrigin: true,
}
},
cssSourceMap: false
},

二。寫好后端接受的代碼:這樣的話后端接收到post請求可以進行處理:

const userApi = require('./api/userApi');
const fs = require('fs');
const path = require('path');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser')
const cors = require('cors');
const express = require('express');
const app = express();

app.use(cors({
origin:['http://localhost:8080'],
methods:['GET','POST'],
alloweHeaders:['Conten-Type', 'Authorization']
}));

app.set('port', (process.env.port || 3000))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: false}))
app.use(cookieParser())

app.use(userApi)

app.listen(app.get('port'), function () {
console.log('Visit http://localhost:' + app.get('port'))
})

router.post('/api/login', function (req, res) {
let userName = req.body.username,
password = req.body.password,
resBody = {state: ''}
if (userName !== undefined && userName.length > 0) {
conn.query("SELECT * FROM users WHERE ?", {name: userName}, function (err, doc) {
if (err) {
resBody.state = '賬號不存在';
res.send(resBody);
} else {
if (doc.length === 0) {
resBody.state = '賬號不存在';
res.send(resBody);
} else {
console.log(doc);
resBody.state = '登錄成功';
res.send(resBody);
}
}
})
}
else {
resBody = {state: '請輸入用戶名'}
res.send(resBody)
}
});

2018.06.10 早上8點到中午12點 沖刺前后端交互成功(vue+express+mysql)

遇到挫折:不管怎么刪除怎么改,讓功能怎么簡化,前端的post請求總是傳不到后端,后端一點反應都沒有。

功能已經刪減的不能再刪減了,刪到后端接收到請求就返回一個驗證成功的res,但還是一點反應都沒有。

然后和前端交流一下,前端login按鈕又調試了一下沒問題。

前端后端都沒問題,于是懷疑代理跨域有的小語法沒有掌握,

瘋狂google,按照上面的方法,反復去嘗試,去修改proxytable,改了幾個版本之后,還是不行。

于是后端又把流程走了一次,發現main里面有一個東西沒配置,那就是:

Vue.use(VueResource);
加上這一句,果然就好了。
啟示:知其然也要知其所以然,不能單純隨便復制一下,按鈕,組件都出來就算完成了。

轉載于:https://www.cnblogs.com/colorfulhw/p/9164996.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/251593.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/251593.shtml
英文地址,請注明出處:http://en.pswp.cn/news/251593.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

web安全

web安全 DOS命令 web攻防必備課筆記 慕課xss學習 阮一峰&#xff1a;MVC、MVP和MVVM的圖示轉載于:https://www.cnblogs.com/hanxuming/p/7774092.html

JavaScript --- 渲染數據量大的數組

很多時候&#xff0c;需要在頁面上展示從后臺來的大量數據,如果一次性渲染&#xff0c;會影響用戶的體驗。(而且瀏覽器中的JS嚴格限制了資源) /* *使用分組的思想來渲染大量的數組 *parmas array 要處理的數組 *params process 對數組中每一個item進行的操作 *parmas context …

Jquery操作select小結

每次操作select都要查資料&#xff0c;干脆總結一下。 為select設置placeholder <select class"form-control selOP" placeholder"Pick Orchestration Plan"><option value"" disabled selected styledisplay:none;>Pick Orchestrat…

第六講:PrintClient工具的使用

一些簡單命令&#xff1a; cp -rf 源目錄 目的目錄 chmod -R 777 文件名 motelist 查看節點路徑 make telosb 編譯代碼 make telosb reinstall 下載但不編譯 make telosb install 編譯并且下載 make telosb install, 2 bsl,/dev/ttyUSB0 下載指定路徑 java net.tinyos.tools.Li…

SQL Server

查看數據庫服務器名稱&#xff1a;tracert 192.168.10.01 轉載于:https://www.cnblogs.com/hongwei2085/p/9174760.html

css --- 選擇器

標簽選擇器 // 標簽選擇器是最簡單的選擇器, 它的命名只要和對應的HTML標簽相同即可 h1 {font-size: 30px;color: #333; }類選擇器 // 類選擇器也稱為class選擇器,它的語法非常簡單,在class名稱前面加上一個"."符號 <div class"red content"></…

C++標準輸入流、輸出流以及文件流

1、流的控制 iomanip 在使用格式化I/O時應包含此頭文件。 stdiostream 用于混合使用C和C 的I/O機制時&#xff0c;例如想將C程序轉變為C程序 2、類繼承關系 ios是抽象基類&#xff0c;由它派生出istream類和ostream類&#xff0c; iostream類支持輸入輸出操作&…

Hadoop學習筆記—8.Combiner與自定義Combiner

一、Combiner的出現背景 1.1 回顧Map階段五大步驟 在第四篇博文《初識MapReduce》中&#xff0c;我們認識了MapReduce的八大步湊&#xff0c;其中在Map階段總共五個步驟&#xff0c;如下圖所示&#xff1a; 其中&#xff0c;step1.5是一個可選步驟&#xff0c;它就是我們今天需…

6-12mysql庫的操作

1&#xff0c;mysql庫的各種分類: nformation_schema&#xff1a; 虛擬庫&#xff0c;不占用磁盤空間&#xff0c;存儲的是數據庫啟動后的一些參數&#xff0c;如用戶表信息、列信息、權限信息、字符信息等.  performance_schema&#xff1a; MySQL 5.5開始新增一個數據庫&am…

css --- 行內框和內容區

css規定font-size的大小實際上是字體的高度 可以將內容區理解為font-size的大小. 行內高可以理解為 ( (line-height) - (font-size) ) /2 然后再font-size 的上下加上前面的值 看下面的例子 <p style"font-size:12px;line-height:12px;">this is text, <em&…

DotNetTextBox V3.0 所見即所得編輯器控件 For Asp.Net2.0(ver 3.0.7Beta) 增加多語言!

英文名&#xff1a;DotNetTextBox V3.0 WYSWYG Web Control For Asp.Net2.0 中文名&#xff1a;DotNetTextBox V3.0 所見即所得編輯器控件 For Asp.Net2.0 類型: 免費控件(保留版權) 作者: 小寶.NET 2.0(Terry Deng) 主頁&#xff1a;http://www.aspxcn.com.cn 控件演示頁面: h…

phantomjs

npm 安裝 phantomjs失敗&#xff0c;解決辦法是到http://phantomjs.org/download.html 下載需要的壓縮包&#xff0c;然后放到%appData%\Local\Temp\phantomjs\下&#xff0c;重新執行npm i 轉載于:https://www.cnblogs.com/tellme/p/7777626.html

js動態刪除行錯誤

Uncaught TypeError: Failed to execute removeChild on Node: parameter 1 is not of type Node. js中出現如上錯誤&#xff0c;檢查驗證document.getElementById&#xff08;&#xff09;中的參數是否傳遞正確&#xff0c; 例&#xff1a; var textnumber parseInt(docume…

css --- 浮動元素與 塊框/行內框重疊時的細節

塊框,可以認為是塊級元素(如div、h1)的內容區 內邊距 行內框可以認為是行內元素(如span)的內容區 內邊距 當 塊級框/行內框 和一個浮動元素重疊時&#xff0c;行內框的邊框、背景和內容都在幅度元素之上&#xff0c;塊級框的邊框和背景都在浮動元素的下面&#xff0c;但內容在…

Android 禁止Viewpager左右滑動功能

做項目要求某種情況下ViewPager不能滑動 百度后發現重寫ViewPager&#xff0c;覆蓋ViewPager的onInterceptTouchEvent(MotionEvent arg0)方法和onTouchEvent(MotionEvent arg0)方法&#xff0c;這兩個方法的返回值都是boolean類型的&#xff0c;只需要將返回值改為false&#x…

error C1853: “Debug\BigBuffer.pch”預編譯頭文件來自編譯器的早期版本,或者預編譯頭為 C++ 而在 C 中使用它(或相反)...

<pre id"best-content-1299104064" mb-10""" style"font-size: 14px; line-height: 28px; ">該錯誤是因為當項目中混合了 .cpp 和 .c 文件時&#xff0c;編譯器會對它們采取不同的編譯方式&#xff08;主要是因為對函數聲明的處理方式…

6.13的練習

#&#xff01;Usr/bin/env python # -*- coding:utf-8 -*- # Author:Alex Li 一個整數&#xff0c;它加上100后是一個完全平方數&#xff0c;再加上268又是一個完全平方數&#xff0c;請問該數是多少&#xff1f;&#xff1a;for i in range(1,1000):for j in range(1,1000):i…

npm --- 包的發布與導入

安裝好NODE后,下面演示如何編寫一個包,并將其發布到NPM倉庫中,最后通過NPM安裝回本地. 以下例子是在windows*64環境下運行的. 1.編寫模塊 exports.sayHello function(){return Hello World; }將上述代碼保存在hello.js中 2.初始化包描述文件: 使用npm init指令,快速生成包…

賬號注冊的form

class RegForm(forms.ModelForm):password forms.CharField(widgetforms.PasswordInput, label密碼, min_length6) # 重寫默認字段re_password forms.CharField(widgetforms.PasswordInput, label確認密碼, min_length6) # 新增字段class Meta:model models.UserProfile …

servlet面試常考 (轉載)

編輯 刪除 1、說一說Servlet生命周期&#xff08;非常重要&#xff09; Servlet生命周期包括三部分&#xff1a; 初始化&#xff1a;Web容器加載servlet&#xff0c;調用init()方法…