bash: express: command not found及vue连接数据库调接口
今天在使用express -e . 的命令时,cmd给我报了一段不识别的错误:
bash: express: command not found
,在网上查了一下,有人指出是express4的版本将命令工具分家了,所以需要我们安装以命令工具:
命令如下:npm install -g express-generator
之后再次安装:npm install -g express
好了,没问题了。
vue连接数据库调接口:
1.在code中安装:express server -e
2.进入server: cd server
3.安装依赖:cnpm i
4.vuex->code->server->app.js添加:
//监听端口
app.listen(777,()=>{
console.log('服务器已经启动...')
});
5.启动 nodemon app
如果显示bash:nodemon:command not found
执行以下命令:
cnpm install -g nodemon
6.引入axios并挂载在vue的原型上
npm install axios --save 在main.js中引入
import axios from 'axios'
Vue.prototype.axios = axios;

在相应页面测试:
this.axios.get('/api/voteindex')
.then(response => {
if(response.data.length){
console.log('接收后端响应登录请求的数据',response.data[0]);
}else{
_this.$message.error('请检查用户名和密码');
}
})
7.vuex->code-vuexms->config->index.js中的dev里配置proxyTable:
proxyTable: {
'/api':{
target: 'http://localhost:777/', // 测试
changeOrigin: true, // 改变源(是否跨域)
pathRewrite: {
'^/api': '/'
}
}
}

8.引入请求
在vuex->code-server->routes->index.js引入:
router.get('/voteindex',(req,res) =>{
res.send("111")
});
9.用node.js连接数据库,启动phpStudy
在server中安装mysql
cnpm install mysql --save
vuex->code-server->routes中新建conn.js
//引入mysql
const mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'vuexms'
}); //暴露出去
module.exports = connection;
// connection.connect();

10.在vuex->code-server->routes->index.js连接数据库
//引入连接数据模块
const connection =require('./conn');
// //连接数据
connection.connect(() => {
console.log("数据库连接成功")
});

bash: express: command not found及vue连接数据库调接口的更多相关文章
- bash:express:command not found
重新设置了node_global和node_cache目录后,总是显示command not found 找了几篇博文后,终于解决了这个问题 步骤如下: 1.新建node_global和node_ ...
- scp报错 -bash: scp: command not found
环境:RHEL6.5 使用scp命令报错: [root@oradb23 media]# scp /etc/hosts oradb24:/etc/ -bash: scp: command not fou ...
- source /etc/profile报错-bash: id:command is not found
由于误操作导致 source /etc/profile 报错 -bash: id:command is not found 此时,linux下很多命令到不能能用,包括vi ls 等... 可以使用 e ...
- -bash: .bash_profile: command not found
今天有一同事安装了ORACLE后,在切换账号时遇到错误提示"-bash: .bash_profile: command not found".如下所示 [root@GLETestL ...
- Linux下提示 bash: xxx command not found
今天在虚拟机上安装了CentOS5.5,发现运行一些很正常的诸如:init,shutdown,fdisk 等命令时,悍然提示: bash: xxx command not found. 那么,首先就要 ...
- [原创]-bash: iostat: command not found解决办法
[root@testhost ~]# iostat-bash: iostat: command not found IOSTAT 命令不可用,首先确认sysstat包是否安装,sysstat包中包括i ...
- # mysql -u root -p -bash: mysql: command not found
[root@jboss ~]# mysql -u root -p-bash: mysql: command not found 需要安装mysql # yum install mysql之后就行 了
- bash:fdisk:command not found
bash:fdisk:command not found [lansir@Red-Hat ~]$ fdisk -l-bash: fdisk: command not found 原因是fdisk不在P ...
- Centos提示-bash: make: command not found的解决办法
一般出现这个-bash: make: command not found提示,是因为安装系统的时候使用的是最小化mini安装,系统没有安装make.vim等常用命令,直接yum安装下即可: yum - ...
随机推荐
- error LNK2001: unresolved external symbol _main解决办法(zz)
error LNK2001: unresolved external symbol _main解决办法 解决外部符号错误:_main,_WinMain@16,__beginthreadex -!t ...
- id(), is, ==, 的区别与小数据池
1. id() 内存地址 s = 'asdf' n = id(s) print(n)输出:16506464 #16506464为变量s的内存地址 2. == 比较数值 3. is 比较内存地址 数字, ...
- day 65 Django基础十一之认证系统
Django基础十一之认证系统 本节目录 一 auth模块 二 User对象 三 扩展默认的auth_user表 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 auth模块 我们 ...
- PAT甲级——A1135 Is It A Red-Black Tree 【30】
There is a kind of balanced binary search tree named red-black tree in the data structure. It has th ...
- 4_1.springboot2.xWeb开发使用thymeleaf
1.简介 如果使用SpringBoot: 1).创建SpringBoot应用,选中我们需要的模块: 2).SpringBoot已经默认将这些场景配置好了,只需要在配置文件中指定少量配置就可以运行起来: ...
- Spring父子上下文(WebApplicationContext)(防止事务失效)
如果你使用了listener监听器来加载配置,一般在Struts+Spring+Hibernate的项目中都是使用listener监听器的.如下 <listener> <listen ...
- tensorflow识别验证码(1)-tensorflow安装,验证码生成
什么是TensorFlow? TensorFlow是Google开发的一款神经网络的Python外部的结构包, 也是一个采用数据流图来进行数值计算的开源软件库.TensorFlow 让我们可以先绘制 ...
- OpenGL键盘交互响应事件
GLUT允许我们编写程序,在里面加入键盘输入控制,包括了普通键,和其他特殊键(如F1,UP).在这一章里我们将学习如何去检测哪个键被按下,可以从GLUT里得到些什么信息,和如何处理键盘输入. 处理 ...
- html-from提交表单
使用form创建的仅仅是一个空白的表单, 我们还需要向form中添加不同的表单项 <!DOCTYPE html> <html> <head> <meta ch ...
- LUOGU P2580 于是他错误的点名开始了(trie树)
传送门 解题思路 trie树模板