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 - ...
随机推荐
- class.forname & classloader
From https://www.cnblogs.com/gaojing/archive/2012/03/15/2413638.html 传统的使用jdbc来访问数据库的流程为: Class.forN ...
- System.DateTime.cs
ylbtech-System.DateTime.cs 1. 程序集 mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5 ...
- mysql中的字符串截取和替换
-- 替换 replace(字段名,"需要替换的字符","替换的字符") mysql里replace不支持正则匹配 mysql> set @needRep ...
- 6_3.springboot2.x数据整合Mybatis(注解和非注解)
1.配置文件 pom.xml 导入mybatis提供的启动器 <dependency> <groupId>org.mybatis.spring.boot</groupId ...
- Spring JdbcTemplate详解(9)
JdbcTemplate简介 Spring对数据库的操作在jdbc上面做了深层次的封装,使用spring的注入功能,可以把DataSource注册到JdbcTemplate之中. JdbcTempla ...
- 3.在vm上安装centos 7
在vm上安装centos 7 1.文件 → 新建虚拟机 3.选择安装Linux系统 4. 虚拟机命名,并选择安装的文件夹 5.选择分配的处理器 6.使用网络地址转换 7.默写选项 9.新建虚拟机 10 ...
- C++开发系列-内联函数
内联函数 C++使用内联函数来替代宏代码片段. #include <iostream> int main(){ printfA(); return 0; } inline void pri ...
- vue+h-ui+layUI完成列表页及编辑页
最近做一个新项目,用H-ui做后台, 比较喜欢他的模仿bootsharp的栅格和表单样式. 感觉不好的是iframe加载速度比较慢. 这里在原有的H-ui页面基础上加入用vue来绑数据,用的还可以. ...
- Extjs & Ext.net中的一些属性
Extjs & Ext.Net 弹出整个浏览器对话框的方法 top.Ext.Msg.alert("值"); top.Ext.Msg.confirm("值" ...
- 锋利的Jquery(Table,Checkbox)
1.Table奇数偶数行 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...