1:scss配置
npm i @nuxtjs/style-resources --save
/*
** Nuxt.js modules
*/
modules: [
// ['nuxt-sass-resources-loader', "~/assets/css/base.scss"] //无效
'@nuxtjs/style-resources',
],
styleResources: {
scss: [
'./assets/css/*.scss',
]
},
2:添加ant-design-vue (plugins/antd-ui.js)
plugins/antd-ui.js
import Vue from 'vue'
import Antd from 'ant-design-vue/lib'
import "ant-design-vue/dist/antd.css";
export default () => {
Vue.use(Antd)
}
nuxt.config.js
plugins:[
"@/plugins/antd-ui",
// { src: "@/plugins/swiper", ssr: false }
],
3.axios配置
plugins 新建axios.js , 并配置到nuxt.config.js的plugins中
第一种直接配置在axios.js
import axios from "axios";
// import qs from "qs";
export function fetch(config) {
return new Promise((resolve, reject) => {
const instance = axios.create({
headers: {
// "Content-Type": "application/json" //以json格式传参
"Content-Type": "application/x-www-form-urlencoded" //以key - val 形式传参
},
timeout: 5000,
baseURL: "http://192.168.2.23:8080/qianlou"
});
// config.data = qs.stringify(config.data); 参数转字符串形式
let params = new URLSearchParams();
for (let key in config.data) {
let val = config.data[key];
if (!config.data[key] && config.data[key] != 0) {
val = "";
}
params.append(key, val);
}
config.data = params;
instance(config)
.then(res => {
console.log(res);
resolve(res);
})
.catch(err => {
console.log(err);
reject(err);
});
});
}
export function getData(url, data, type) {
!type && (type = "post");
return fetch({ url, method: type, data });
}
页面
import { getData } from "~/plugins/axios.js";
getData("api/xxx", {});
第二种 axios配置到外层,导入axios中;
4.express 配置
问题一:get请求能拿到,post不走;
import { Router } from "express";
const myrouter = require("./router.js");
var router = Router();
router.get("/user", myrouter.indexShow);
router.post("/user", myrouter.indexShow);
export default router;