$ cnpm install nuxt-helpers
Collection of useful and SSR compatible vue plugins for using with nuxt.js
1- Install nuxt-helpers package:
# YARN
yarn add nuxt-helpers
# NPM
npm install nuxt-helpers
2- Change your nuxt.config.js
:
const NuxtHelpers = require('nuxt-helpers');
module.exports = NuxtHelpers([
//'auth',
//'axios',
//'bootstrap',
//'dev',
//'meta',
//'toast',
//'optimize',
//'font-awesome',
//'moment',
//'offline',
// 'manifest',
//'vendor',
], {
// Your nuxt config
})
3- Add .nuxt-helpers
to your .gitignore
file
This plugin is a wrapper around axios. It tries to resolve and make easier lot's of ajax tasks specially with SSR. So you can use $get('profile') instead of (await Axios.get('http://server/api/profile')).data
.
$get
,$post
,... into vue context instances so requests can be done out-of-the-box.setToken
function so we can easily and globally set authentication tokens.axios
to project package.json
axios
helperimport {$get} from '~/nuxt-helpers/axios';
async data() {
let {profile} = await $get('profile');
return {profile}
}
Or In any other function: (This does not needs importing axios plugin)
mounted() {
let {profile} = await this.$get('profile');
return {profile}
}
Customization
Customization can be done using shared environment variables.
Environment variable | Default | Description |
---|---|---|
API_URL | http://localhost:3000 | Base url for ajax requests in server-side |
API_URL_BROWSER | [API_URL] | Base url for ajax requests in client-side |
API_PREFIX | /api | Adds this prefix before all relative urls |
With bootstrap-vue you can easily use standard bootstrap 4 components with your app. (you need to add bootstrap package in your package.json too)
bootstrap-vue
to package.json
bootstrap-vue
helper<template>
<b-alert show>
Hello Bootstrap!
</b-alert>
</template>
Easy toasts for your app using mini-toastr.
mini-toastr
to package.jsontoast
helperThen you can define notification in your routes or components:
export default {
methods:{
async login() {
try {
await this.$post('auth/login');
this.$success('Welcome :)');
} catch(e){
this.$error('Error while authenticating');
}
}
}
}
cookie
& js-cookie
to package.jsonauth
helper// store/auth.js
import AuthStore from '~/.nuxt-helpers/auth';
const authStore = new AuthStore({ /*opts*/ });
// Your customizations
export default authStore;
Options
state.auth.user
. (overrides using Object.assign when logged-in).Leverage Font Awesome the iconic font and CSS toolkit.
font-awesome
to package.jsonfont-awesome
helperThis helper is not stable yet.
app
and vendor
and sets assets public path to /assets
.cssnano
to package.jsonoptimize
helperThis helper is not stable yet.
This helper only works in non dev mode
cacheName
to allow having multi apps in same domain.offline
helperThis helper is not stable yet.
Adds Web App Manifest with no pain.
static/manifest.json
<link rel=manifest>
to pages if not exits.<link rel=favicon>
to pages if not exits.<meta name=description>
to pages if not exits.<meta name=theme-color>
to pages if not exits.manifest
helperstatic/icon.png
for your app icon.nuxt.manifest
to override defaults:manifest:{
name:'My Awesome App',
dir:'rtl'
}
This awesome little helpers creates junction symlinks from nodule_modules
into static/vendor
so you can directly serve node modules inside web. Useful for runtime dependencies.
vendor
helper/static/vendor
to .gitignore
nuxt.config.json
inside vendor
section:{
vendor: ['ckeditor']
}
If you are migrating from <= 0.7.0 version:
.nuxt-helpers
to .gitignore
.axios
and auth
usage description.bootstrap
plugin is renamed to bootstrap-vue
.notifications
plugin is renamed to toast
and usage simplified.Any contribution,bug report or component is highly welcomed :)
Contributors
MIT License - Fandogh 2017
Copyright 2014 - 2016 © taobao.org |