Last active
March 9, 2018 09:38
-
-
Save imyelo/48872fc76468c86b1feb893a98a216fa to your computer and use it in GitHub Desktop.
tinajs - intro example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- /app.mina --> | |
<config> | |
{ | |
"pages": [ | |
"pages/home.mina", | |
] | |
} | |
</config> | |
<script> | |
import Tina from '@tinajs/tina' | |
import router from '@tinajs/tina-router' | |
Tina.use(router) | |
App() | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- /pages/home.mina --> | |
<config> | |
{ | |
"usingComponent": { | |
"logo": "../components/logo.mina" | |
} | |
} | |
</config> | |
<template> | |
<view> | |
<text>I'm {{ name }}. </text> | |
<button bindtap="sayHi">Say Hi</button> | |
<logo /> | |
</view> | |
</template> | |
<script> | |
import { Page } from '@tinajs/tina' | |
import { fetchUser } from '../api' | |
Page.define(({ | |
data: { | |
firstname: 'Tina', | |
lastname: 'S', | |
}, | |
// 由 tina 集成的计算属性能力 | |
compute ({ firstname, lastname }) { | |
return { | |
name: `${firstname} ${lastname}`, | |
} | |
}, | |
async onLoad () { | |
// 由 tina-router 提供的路由能力扩展 | |
let { id } = this.$route.query | |
try { | |
let { firstname, lastname } = fetchUser(id) | |
this.setData({ firstname, lastname }) | |
} catch (error) { | |
this.$router.redirect(`/pages/login?from=${this.$route.fullPath}`) | |
} | |
}, | |
methods: { | |
sayHi () { | |
wechat.showModal({ | |
title: `Hi ${this.data.name}`, | |
}) | |
}, | |
}, | |
})) | |
</script> | |
<style> | |
view { | |
padding: 30px 20px; | |
} | |
button { | |
margin: 20px 0; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
carbon setting