wp-nuxt | The module adds WP-API to your nuxt application | Content Management System library

 by   yashha JavaScript Version: 1.0.30 License: MIT

kandi X-RAY | wp-nuxt Summary

kandi X-RAY | wp-nuxt Summary

wp-nuxt is a JavaScript library typically used in Web Site, Content Management System, Vue, Next.js, Wordpress applications. wp-nuxt has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can install using 'npm i wp-nuxt' or download it from GitHub, npm.

The module adds WP-API to your nuxt application.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              wp-nuxt has a low active ecosystem.
              It has 207 star(s) with 18 fork(s). There are 3 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 2 open issues and 3 have been closed. On average issues are closed in 34 days. There are 25 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of wp-nuxt is 1.0.30

            kandi-Quality Quality

              wp-nuxt has 0 bugs and 0 code smells.

            kandi-Security Security

              wp-nuxt has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              wp-nuxt code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              wp-nuxt is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              wp-nuxt releases are not available. You will need to build from source code and install.
              Deployable package is available in npm.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of wp-nuxt
            Get all kandi verified functions for this library.

            wp-nuxt Key Features

            No Key Features are available at this moment for wp-nuxt.

            wp-nuxt Examples and Code Snippets

            No Code Snippets are available at this moment for wp-nuxt.

            Community Discussions

            QUESTION

            Nuxt generate with vuex and multi-language site
            Asked 2021-Mar-18 at 11:35

            I am currently building my first (statically generated) website with nuxt and a headless Wordpress as CMS. I am also using the module nuxt-i18n for multi-language support: German (default) and English.

            The setup

            To fetch data from the multi-language Wordpress I use the module wp-nuxt and then store the data from the CMS in thes vuex store. Dependent on the client browser language or when the language is changed by the user manually, the endpoint of $wp (wp-nuxt) is changed, so the appropiate content will be fetched and stored in the store.

            Now, on NuxtServerInit() some basic data is fetched from the CMS for the locale defined by the route (e.g. http://myserver/en/news will fetch basic data from the english CMS endpoint http://wphost/mycms/en/wp-json/wp/v2/..., see /en/ in endpoint). For each layout/page further content is fetched via asyncData() and fetch(), also, of course, for the current locale.

            The problem

            This works fine, as long nuxt is ran via nuxt dev. If the locale is switched by the user, the fetches for the other locale will be handled by asyncData() and fetch() on the client.

            nuxt generate works also for the locale the site was first loaded with, however has troubles when switching locales: The data is not found in the store.

            My guess is: On generate nuxt is calling nuxtServerInit(), asyncData() and fetch() for each route. This will fill the store of each route with the routes locale data. For DE-Routes (e.g. myserver/impressum) german content, for EN-routes (e.g. myserver/en/site-notice) english content. But if the locale is changed by the user, the stores of these routes only contain content for the current locale and asyncData() and fetch() won't be called to fill the store (of course, this is by design of generate).

            Consequently, it seems to me that nuxt is storing different "vuex store instances" for the different routes and cannot switch to the store on user initiated locale switch.

            Possible workarounds

            There are a few simple workarounds I already tried and seem to solve the issue but are far from perfect:

            1. Trigger a reload on language switch, so the site is realoaded and nuxt is loading the store for the route with the correct locale. - I don't like it, it feels hacky.

            2. Fill the store via nuxtServerInit() with data of both languages, by fetching against both CMS endpoints. - I don't like it either, it feels hacky and although it may work for two languages this has huge overhead, the more content the CMS has.

            I hope I was able to describe the problem appropriately. Is there something I am missing? I haven't found anything on this, so far. I would appreciate if you have any thoughts on that.

            Thanks, Valentin

            ...

            ANSWER

            Answered 2021-Mar-18 at 11:35

            Cause of the problem

            I finally got to the source of the issue. I will share my misconceptions with you so it might help someone with similar setup.

            So first of all, on generate saves the results of the nuxtServerInit() of the store and the asyncData() and fetch() of the layout and page components for each route in a payload.js file to simulate the API calls on the generated static site (https://nuxtjs.org/blog/going-full-static/#crazy-fast-static-applications).

            When writing the original post, I did two things, which made nuxt not store the whole payload of the fetch() method of each page component when switching language manually:

            1. On nuxtServerInit() I fetched some API data for all routes (e.g. site title, list of main pages for the navbar, etc.)

            2. On fetch() in the page components I fetched needed resources only if these were not already in the nuxt store. This would make sense imho in a SSR/SPA site, because you don't need to fetch (and wait), if you already have the data.

            Consequently, this means nuxt generate fetches this data for each page with nuxtServerInit() saving the payload associated with nuxtServerInit. However, it does not save the payload on fetch() because the if condition in the page component's fetch() method at the time of generation returns false - because the data was fetched already with nuxtServerinit().

            As a result, switching the locale on the generated static site triggered the simulated fetch() for the routes page component, but the payload for this method didn't contain the data.

            Solution

            The simplest solution is to not fetch any or at least any locale-specific data on nuxtServerInit() if isStatic is true and do the fetching in page or layout components.

            Source https://stackoverflow.com/questions/66654246

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install wp-nuxt

            Add wp-nuxt dependency using yarn or npm to your project. Add wp-nuxt to modules section of nuxt.config.js. Info: when you pass extensions: true you will have additional functions of wpapi-extensions available. For this you also have to install WUXT Headless WordPress API Extensions on your wordpress sever.
            Add wp-nuxt dependency using yarn or npm to your project
            Add wp-nuxt to modules section of nuxt.config.js

            Support

            IE11 seems to work, but throws errors. (Help wanted).
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • npm

            npm i wp-nuxt

          • CLONE
          • HTTPS

            https://github.com/yashha/wp-nuxt.git

          • CLI

            gh repo clone yashha/wp-nuxt

          • sshUrl

            git@github.com:yashha/wp-nuxt.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Consider Popular Content Management System Libraries

            Try Top Libraries by yashha

            percollate-api

            by yashhaTypeScript

            wpapi-extensions

            by yashhaTypeScript

            nuxt-ts-starter

            by yashhaJavaScript