nuxt.js

Vuex and Axios in asyncData

流过昼夜 提交于 2019-12-24 00:26:21
问题 I want to access my Vuex data in asyncData but I can't. Also I can't seem to be able to use axios module in asyncData. I tried a lot. pages/index.vue export default { asyncData() { //in my project there's a lot more code here but i think this is enough let id = this.$store.state.id //i know i should prob use getter but no //here i want to do an axios req with this var "id" but axios doesnt work return axios.get(`url${id}`) .then(...) //not gonna write it out here } } store/index.js export

Nuxt/Vue.js - Dynamically loading in a child component based on a prop

三世轮回 提交于 2019-12-23 12:53:33
问题 I have a sectionHeader.vue component that I want to use on lots of different pages. Inside that sectionHeader.vue is a <canvas> element (that I am using for some robust three.js animations) that I dynamically want to change inside of each header through props. I'd like to get this working to take advantange of Vue's inherent code-splitting so that each page doesn't load every single other pages animation js code, only the code that is relevant to it. I'm attempting to dynamically load this in

How to access to the vue store in the asyncData function of nuxt

泪湿孤枕 提交于 2019-12-23 07:28:46
问题 in a component i want to acces to the store with the asyncData function like so : asyncData({ app, params }) { var url = `https://myapi/news/${app.$store.state.market}/detail/${params.id}`; return app.$axios.get(url).then(response => { return { actu: response.data }; }); } but i received "Cannot read property 'state' of undefined" is there another to receive the state of the store here ? 回答1: You need to get store from context. Reference asyncData({ app, params, store }) { var url = `https:/

NuxtJS & SASS Loader - Build with sass-loader (SCSS) on production

陌路散爱 提交于 2019-12-22 12:41:44
问题 I've added this lines to build with sass-loader on development (local) server: nuxt.config.js module.exports = { mode: 'spa', build: { analyze: { analyzerMode: 'static', generateStatsFile: true, statsFilename: 'webpack-stats.json', openAnalyzer: false }, vendor: [ 'axios', 'vuetify' ], extend (config) { config.resolve.alias['vue'] = 'vue/dist/vue.common' const vueLoader = config.module.rules.find((rule) => rule.loader === 'vue-loader') vueLoader.options.loaders.scss = 'vue-style-loader!css

How to deploy nuxt.js project on shared hosting?

烈酒焚心 提交于 2019-12-22 06:42:07
问题 Is it possible to deploy nuxt-js spa project in shared hosting like hostgator through cpanel? I have tried several time to run below command, it's generate dist folder but didn't work. My command: npm run build Can you help me please? 回答1: npm run build Builds files for `npm run start` serving. And looks like you want it to be static files, which you just upload to hosting. So you should run: npm run generate then in `/dist/` you will find static spa. 来源: https://stackoverflow.com/questions

NUXT- assets and static folder - when to use which?

浪子不回头ぞ 提交于 2019-12-22 03:52:16
问题 Being new to NUXT, I am a bit confused about the difference between the assets and static folders. in the documentation regarding this folders it says: every file below 1 KB will be inlined as base-64 data URL. Otherwise, the image/font will be copied in its corresponding folder (under the .nuxt directory) with a name containing a version hashes for better caching. and also: If you don't want to use webpacked Assets from the assets directory, you can create and use the static directory in

Nuxtjs bad request api 400 axios error production and dev good

徘徊边缘 提交于 2019-12-22 01:45:27
问题 I have a problem that I can not solve for the production my api does not work on the front end, when I directly test the API it works. I do not understand, locally it works perfectly, in production it has a problem. MY SCRIPT My page index.js async asyncData({ store }) { const posts = await store.dispatch("post/fetchPostAll"); return { posts }; }, My page store.js async fetchPostAll({ commit }) { try { return await this.$axios.$get('/api/post'); } catch (e) { commit('setError', e, { root:

How to read POST request parameters in nuxtjs?

你。 提交于 2019-12-21 06:25:10
问题 is there some simple way how to read POST request parameters in nuxtjs asyncData function? Thanks a lot. Here's an example: Form.vue: <template> <form method="post" action="/clickout" target="_blank"> <input type="hidden" name="id" v-model="item.id" /> <input type="submit" value="submit" /> </form> </template> submitting previous form routes to following nuxt page: Clickout.vue async asyncData(context) { // some way how to get the value of POST param "id" return { id } } 回答1: Finally I found

How to read POST request parameters in nuxtjs?

旧时模样 提交于 2019-12-21 06:25:03
问题 is there some simple way how to read POST request parameters in nuxtjs asyncData function? Thanks a lot. Here's an example: Form.vue: <template> <form method="post" action="/clickout" target="_blank"> <input type="hidden" name="id" v-model="item.id" /> <input type="submit" value="submit" /> </form> </template> submitting previous form routes to following nuxt page: Clickout.vue async asyncData(context) { // some way how to get the value of POST param "id" return { id } } 回答1: Finally I found

Vue.js: Uncaught promises in vuex actions

僤鯓⒐⒋嵵緔 提交于 2019-12-21 05:21:36
问题 I understand vuex actions return promises, but I haven't found the ideal pattern to handle errors in vuex. My current approach is to use an error interceptor on my axios plugin, then committing the error to my vuex store. in plugins/axios.js : export default function({ $axios, store }) { $axios.onError(error => { store.dispatch('setError', error.response.data.code); }); } in store/index.js : export const state = () => ({ error: null, }); export const mutations = { SET_ERROR(state, payload) {