Commit 8ed69f71 authored by shangbj's avatar shangbj

增加axios

parent 8852d477
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
</template> </template>
<script> <script>
import axios from '~/plugins/axios'
export default { export default {
data:()=>{ data:()=>{
return{ return{
...@@ -33,9 +35,9 @@ export default { ...@@ -33,9 +35,9 @@ export default {
}, },
mounted() { mounted() {
// console.log(this.$store); // console.log(this.$store);
this.$axios.$get('/api/news?pageIndex=1&pageSize=20&type=simplify').then(res => { axios.get('/api/news?pageIndex=1&pageSize=20&type=simplify').then(res => {
if (res.result) { if (res.data.result) {
this.newsData = res.data; this.newsData = res.data.data;
// this.$store.commit('newsScrollData',res.data); // this.$store.commit('newsScrollData',res.data);
} else { } else {
this.newsData = []; this.newsData = [];
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"precommit": "npm run lint" "precommit": "npm run lint"
}, },
"dependencies": { "dependencies": {
"axios": "^0.18.0",
"@nuxtjs/axios": "^5.3.1", "@nuxtjs/axios": "^5.3.1",
"@nuxtjs/proxy": "^1.2.4", "@nuxtjs/proxy": "^1.2.4",
"element-ui": "^2.4.4", "element-ui": "^2.4.4",
......
...@@ -100,21 +100,24 @@ ...@@ -100,21 +100,24 @@
import News from '~/components/index/News.vue' import News from '~/components/index/News.vue'
import Profile from '~/components/index/Profile.vue' import Profile from '~/components/index/Profile.vue'
import ContactUs from '~/components/ContactUs.vue' import ContactUs from '~/components/ContactUs.vue'
import axios from '~/plugins/axios'
export default { export default {
async asyncData({ app }) { async asyncData({ app }) {
const newsData = await app.$axios.$get('/api/news?pageSize=10&type=simplify'); const newsData = await axios.get('/api/news?pageSize=10&type=simplify');
const productData = await app.$axios.$get('/api/product'); const productData = await axios.get('/api/product');
const qualificationsData = await app.$axios.$get('/api/qualifications?pageSize=20&type=simplify'); const qualificationsData = await axios.get('/api/qualifications?pageSize=20&type=simplify');
return { return {
newsData: newsData.data||[], newsData: newsData.data.data||[],
productData:[...productData.ozonizer.data,...productData.disinfectant.data,...productData.equipment.data], productData:[...productData.data.ozonizer.data,...productData.data.disinfectant.data,...productData.data.equipment.data],
qualificationsData: qualificationsData.data||[], qualificationsData: qualificationsData.data.data||[],
} }
}, },
data:function(){ data:function(){
return { return {
engineeringData:this.$store.state.engineeringData, engineeringData:this.$store.state.engineeringData,
productData:[],
qualificationsData:[],
} }
}, },
components: { components: {
......
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
</div> </div>
</template> </template>
<script> <script>
import axios from '~/plugins/axios'
export default { export default {
async asyncData({ app, params, error }) { async asyncData({ app, params, error }) {
const details = await app.$axios.$get(`/api/news/detail/${params.id}`); const details = await axios.get(`/api/news/detail/${params.id}`);
if(details.result){ if(details.data.result){
return {details: details.data}; return {details: details.data.data};
}else{ }else{
return error({ message: '页面不存在', statusCode: 404 }) return error({ message: '页面不存在', statusCode: 404 })
} }
......
...@@ -22,10 +22,12 @@ ...@@ -22,10 +22,12 @@
</div> </div>
</template> </template>
<script> <script>
import axios from '~/plugins/axios'
export default { export default {
async asyncData({ app }) { async asyncData({ app }) {
const newData = await app.$axios.$get('/api/news?pageIndex=1&pageSize=20&type=simplify'); const newData = await axios.get('/api/news?pageIndex=1&pageSize=20&type=simplify');
return { newData: newData.data || [] ,total:newData.total} return { newData: newData.data.data || [] ,total:newData.data.total}
}, },
data(){ data(){
return{ return{
......
import * as axios from 'axios' import * as axios from 'axios'
import Vue from 'vue'
let options = {} let options = {}
// The server-side needs a full url to works // The server-side needs a full url to works
...@@ -7,6 +6,4 @@ if (process.server) { ...@@ -7,6 +6,4 @@ if (process.server) {
options.baseURL = `http://${process.env.HOST || 'localhost'}:${process.env.PORT || 3000}` options.baseURL = `http://${process.env.HOST || 'localhost'}:${process.env.PORT || 3000}`
} }
export default () => { export default axios.create(options)
Vue.use(axios.create(options))
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment