|
| 1 | +# @nuxtjs/python |
| 2 | +[](https://npmjs.com/package/@nuxtjs/python) |
| 3 | +[](https://npmjs.com/package/@nuxtjs/python) |
| 4 | +[](https://circleci.com/gh/https://github.com/nuxt-community/python-module) |
| 5 | +[](https://codecov.io/gh/https://github.com/nuxt-community/python-module) |
| 6 | +[](https://david-dm.org/https://github.com/nuxt-community/python-module) |
| 7 | +[](http://standardjs.com) |
| 8 | + |
| 9 | +> Write Nuxt.js Apps in Python |
| 10 | +
|
| 11 | +[📖 **Release Notes**](./CHANGELOG.md) |
| 12 | + |
| 13 | +## Features |
| 14 | + |
| 15 | +- Write Nuxt.js applications without using Python! |
| 16 | +- Currently only supports custom Javascripthon but in the future other compilers will also be expected to work. |
| 17 | + |
| 18 | +## Setup |
| 19 | +- Add `@nuxtjs/python` dependency using yarn or npm to your project |
| 20 | +- Add `@nuxtjs/python` to `modules` section of `nuxt.config.js` |
| 21 | + |
| 22 | +```js |
| 23 | +{ |
| 24 | + modules: [ |
| 25 | + // Simple usage |
| 26 | + '@nuxtjs/python' |
| 27 | + ] |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +- Install a Python transpiler (e.g. `pip install --user -r requirements.txt`) |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +### Using `.vue` files |
| 36 | +**TIP** If you use Vim you can get the full experience with https://github.com/posva/vim-vue/pull/97 |
| 37 | + |
| 38 | +`hello.vue`: |
| 39 | +```html |
| 40 | +<template> |
| 41 | + <div> |
| 42 | + Nuxt {{ best_lang }} |
| 43 | + </div> |
| 44 | +</template> |
| 45 | +<script lang="py?compiler=pj"> |
| 46 | +class Component: |
| 47 | +
|
| 48 | + def __init__(self): |
| 49 | + self['data'] = lambda: { 'best_lang': 'Python' } |
| 50 | +
|
| 51 | +__all__ = Component() |
| 52 | +</script> |
| 53 | +``` |
| 54 | +Note: This syntax requires a specific branch of Javascripthon until patches get merged https://github.com/icarito/metapensiero.pj/tree/default_import - see alternative with `require` at https://github.com/martim00/python-webpack-loader/pull/8#issuecomment-359280782 |
| 55 | + |
| 56 | +### Using `.py` files for other nuxt files |
| 57 | + |
| 58 | +`store/index.py` |
| 59 | +```python |
| 60 | +from vuex import Vuex |
| 61 | + |
| 62 | + |
| 63 | +def increment(state): |
| 64 | + state.counter = state.counter + 1 |
| 65 | + |
| 66 | + |
| 67 | +def createStore(): |
| 68 | + return Vuex.Store(state={'counter': 0}, |
| 69 | + mutations={'increment': increment}) |
| 70 | + |
| 71 | + |
| 72 | +__all__ = createStore |
| 73 | +``` |
| 74 | + |
| 75 | +`pages/counter.vue` |
| 76 | +```html |
| 77 | +<template> |
| 78 | + <h2>{{ $store.state.counter }}</h2> |
| 79 | + <button @click="$store.commit('increment')">+1</button> |
| 80 | +</template> |
| 81 | +``` |
| 82 | + |
| 83 | +## Development |
| 84 | + |
| 85 | +- Clone this repository |
| 86 | +- Install dependnecies using `yarn install` or `npm install` |
| 87 | +- Start development server using `npm run dev` |
| 88 | + |
| 89 | +## License |
| 90 | + |
| 91 | +[MIT License](./LICENSE) |
| 92 | + |
| 93 | +Copyright (c) Sebastian Silva <[email protected]> |
0 commit comments