├── .gitignore ├── README.md ├── components ├── Banner.vue ├── Feed.vue └── NavBar.vue ├── layouts └── default.vue ├── logo.png ├── netlify.toml ├── nuxt.config.js ├── package.json ├── pages ├── article │ └── _slug.vue ├── editor.vue ├── index.vue ├── login.vue ├── profile │ └── _username.vue ├── register.vue └── settings.vue ├── plugins └── axios.js ├── static └── favicon.ico └── store └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | yarn.lock 4 | .nuxt 5 | dist 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ![RealWorld Example App](logo.png) 2 | 3 | [![RealWorld Frontend](https://img.shields.io/badge/realworld-frontend-%23783578.svg)](http://realworld.io) 4 | 5 | > ### [Nuxt.js](https://nuxtjs.org) codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the [RealWorld](https://github.com/gothinkster/realworld) spec and API. 6 | 7 | ### [Demo](http://realworld-nuxt.netlify.com)    [RealWorld](https://github.com/gothinkster/realworld) 8 | 9 | This codebase was created to demonstrate a fully fledged fullstack application built with **[Nuxt.js](https://nuxtjs.org)** including CRUD operations, authentication, routing, pagination, and more. 10 | 11 | We've gone to great lengths to adhere to the **[Nuxt.js](https://nuxtjs.org)** community styleguides & best practices. 12 | 13 | For more information on how to this works with other frontends/backends, head over to the [RealWorld](https://github.com/gothinkster/realworld) repo. 14 | 15 | # How it works 16 | 17 | > TODO: Describe the general architecture of your app here 18 | 19 | # Getting started 20 | 21 | ```bash 22 | git clone https://github.com/anishkny/realworld-nuxt 23 | cd realworld-nuxt 24 | npm install 25 | npm run dev 26 | ``` 27 | -------------------------------------------------------------------------------- /components/Banner.vue: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /components/Feed.vue: -------------------------------------------------------------------------------- 1 | 42 | 43 | 110 | -------------------------------------------------------------------------------- /components/NavBar.vue: -------------------------------------------------------------------------------- 1 | 44 | -------------------------------------------------------------------------------- /layouts/default.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 19 | 20 | 35 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkny/realworld-nuxt/003dcad27be7f3bb889a3ea0b117ce5714787d1c/logo.png -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [Settings] 2 | ID = "realworld-nuxt" 3 | 4 | [build] 5 | publish = "dist/" 6 | command = "npm run build" 7 | -------------------------------------------------------------------------------- /nuxt.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 3 | mode: 'spa', 4 | 5 | head: { 6 | title: 'Conduit', 7 | meta: [ 8 | { charset: 'utf-8' }, 9 | { name: 'viewport', content: 'width=device-width, initial-scale=1' }, 10 | ], 11 | link: [ 12 | { rel: 'stylesheet', href: '//code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css' }, 13 | { rel: 'stylesheet', href: '//fonts.googleapis.com/css?family=Titillium+Web:700|Source+Serif+Pro:400,700|Merriweather+Sans:400,700|Source+Sans+Pro:400,300,600,700,300italic,400italic,600italic,700italic' }, 14 | { rel: 'stylesheet', href: '//demo.productionready.io/main.css' }, 15 | ], 16 | }, 17 | 18 | modules: [ 19 | '@nuxtjs/axios', 20 | '@nuxtjs/markdownit', 21 | ], 22 | 23 | plugins: [ 24 | '~/plugins/axios', 25 | ], 26 | 27 | markdownit: { 28 | injected: true 29 | }, 30 | 31 | } 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "dev": "nuxt", 4 | "build": "nuxt build" 5 | }, 6 | "dependencies": { 7 | "@nuxtjs/axios": "^5.3.1", 8 | "@nuxtjs/markdownit": "^1.2.1", 9 | "moment": "^2.22.1", 10 | "nuxt": "^1.4.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /pages/article/_slug.vue: -------------------------------------------------------------------------------- 1 | 83 | 84 | 147 | -------------------------------------------------------------------------------- /pages/editor.vue: -------------------------------------------------------------------------------- 1 | 20 | -------------------------------------------------------------------------------- /pages/index.vue: -------------------------------------------------------------------------------- 1 | 43 | 44 | 75 | -------------------------------------------------------------------------------- /pages/login.vue: -------------------------------------------------------------------------------- 1 | 28 | 29 | 52 | -------------------------------------------------------------------------------- /pages/profile/_username.vue: -------------------------------------------------------------------------------- 1 | 48 | 49 | 84 | -------------------------------------------------------------------------------- /pages/register.vue: -------------------------------------------------------------------------------- 1 | 29 | 30 | 55 | -------------------------------------------------------------------------------- /pages/settings.vue: -------------------------------------------------------------------------------- 1 | 38 | 39 | 102 | -------------------------------------------------------------------------------- /plugins/axios.js: -------------------------------------------------------------------------------- 1 | export default function({ $axios, redirect, store }) { 2 | $axios.defaults.baseURL = 'https://conduit.productionready.io/api'; 3 | 4 | $axios.onRequest(config => { 5 | const user = store.getters.user; 6 | if (user && user.token) { 7 | config.headers['Authorization'] = `Token ${user.token}`; 8 | } else { 9 | delete config.headers['Authorization']; 10 | } 11 | }); 12 | 13 | $axios.onError(error => { 14 | const code = parseInt(error.response && error.response.status); 15 | if (code === 401) { 16 | console.log(401); 17 | store.commit('setUser', null); 18 | redirect('/login'); 19 | } 20 | }); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkny/realworld-nuxt/003dcad27be7f3bb889a3ea0b117ce5714787d1c/static/favicon.ico -------------------------------------------------------------------------------- /store/index.js: -------------------------------------------------------------------------------- 1 | import Vuex from 'vuex'; 2 | import axios from 'axios'; 3 | 4 | const createStore = () => { 5 | return new Vuex.Store({ 6 | 7 | state: { 8 | user: getUserFromLocalStorage(), 9 | }, 10 | 11 | mutations: { 12 | setUser(state, user) { 13 | localStorage.setItem('user', JSON.stringify(user)); 14 | state.user = user; 15 | setAxiosAuthHeader(user); 16 | }, 17 | }, 18 | 19 | getters: { 20 | user(state) { 21 | return state.user; 22 | } 23 | }, 24 | 25 | }) 26 | }; 27 | 28 | export default createStore; 29 | 30 | function getUserFromLocalStorage() { 31 | let user = null; 32 | try { 33 | user = JSON.parse(localStorage.getItem('user')); 34 | setAxiosAuthHeader(user); 35 | return user; 36 | } catch (ex) { 37 | localStorage.setItem('user', null); 38 | return null; 39 | } 40 | } 41 | 42 | function setAxiosAuthHeader(user) { 43 | // if (user && user.token) { 44 | // axios.defaults.headers.common['Authorization'] = `Token ${user.token}`; 45 | // } else { 46 | // delete axios.defaults.headers.common['Authorization']; 47 | // } 48 | } 49 | --------------------------------------------------------------------------------