Write Nuxt 2 applications using Python! [Experimental]
MIT License
Write Nuxt.js Apps in Python
npm install # or use yarn
pip install -r requirements.txt
npm run dev
@nuxtjs/python
dependency using yarn or npm to your project@nuxtjs/python
to modules
section of nuxt.config.js
{
modules: [
'@nuxtjs/python'
],
python: {
compiler: 'pj' // default
}
}
<script lang="py">
.compiler
parameter)Compiler default and recommended is Javascripthon but it is possible to use other compilers (see below).
Install the Javascripthon Python transpiler. For now you'll need the master branch e.g:
pip install -e git+https://gitlab.com/metapensiero/metapensiero.pj#egg=javascripthon
Note that Javascripthon requires that you have Python 3.5 (or better).
Javascripthon supports converting Python import statements to ES6 imports as used in Nuxt. Please note syntax conversions.
You can pass a compiler
option to py-loader by using module options or in a python
section in your nuxt.config.js
file.
Transcrypt
has its own module system so in order to use it, you can use the CommonJS module standard (require
to import and module.exports
) and it should work. See the py-loader
Vuejs example.
.vue
filesTIP If you use Vim you can get syntax highlighting for HTML, CSS and Python by installing vim-vue plugin and applying this patch.
hello.vue
:
<template>
<div>
Nuxt {{ best_lang }}
</div>
</template>
<script lang="py">
class Component:
def __init__(self):
self['data'] = lambda: { 'best_lang': 'Python' }
__default__ = Component()
</script>
.py
files for other nuxt filesstore/index.py
from vuex import Store
def increment(state):
state.counter = state.counter + 1
def createStore():
return Store(
state={'counter': 0},
mutations={'increment': increment}
)
__default__ = createStore
pages/counter.vue
<template>
<h2>{{ $store.state.counter }}</h2>
<button @click="$store.commit('increment')">+1</button>
</template>
👉 For a working example, see here.
yarn install
or npm install
npm run dev
Copyright (c) Sebastian Silva [email protected]
This module was started from the module-template by Pooya Parsa and relies heavily on python-webpack-loader by Martim Nascimento and Javascripthon by Alberto Berti.