vue init nuxt/starter
yarn install
yarn run start
"config": {
"nuxt": {
"host": "0.0.0.0",
"port": "3333"
}
}
设置端口号.png
// 设置每个页面的title 和ico,(每个页面就是一个页面,页面都有head这个钩子函数。)
head() {
return {
title: "新闻页面",
meta: [
{ charset: "utf-8" },
{ name: "viewport", content: "width=device-width, initial-scale=1" },
{ hid: "description", name: "description", content: "Nuxt.js project" },
{ name: "renderer", content: "webkit" },
],
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon1.ico" }],
};
},
title和ico.png
css: [
'~assets/css/reset.css', 'element-ui/lib/theme-chalk/index.css'
],
在assets中创建css文件夹,在里面创建reset.css文件,然后在nuxt.config.js中引入。
样式初始化.png
代码一.png
代码2.png
error.png
// 服务端接口请求
async asyncData() {
// 如何在这里发送多个请求,数据返回出去就是直接绑定在this上
//服务端渲染,接口统一在这里请求数据
const siteConfigResult = await axios.post(
"/navigation/rubik/detail",
{ rubikId: 5, type: 5 }
);
// console.log(siteConfigResult.data.result.randomData);
let list = siteConfigResult.data.result.randomData;
const postsResult = await axios.post(
"/navigation/rubik/detail",
{ rubikId: 5, type: 5 }
);
// 对象解构的形式
const { data } = await axios.get(
"https://jsonplaceholder.typicode.com/posts"
);
const { bodyList } = await axios.get(
"https://jsonplaceholder.typicode.com/posts"
);
// console.log(bodyList);
// console.log( bodyList );
let list2 = postsResult.data.result.randomData;
// 返回的数据直接绑定在this上
return {
list,
list2,
posts: data.slice(0, 5),
};
},
asyncData.png