⏳ Loading plugin for Tina.js
- Download package from npm
npm i --save @tinajs/tina-loading
- Install into Tina
// app.js
import Tina from '@tinajs/tina'
import loading from '@tinajs/tina-loading'
Tina.use(loading)
Normally use $loading.push()
and $loading.pop()
methods:
// pages/some-page.js
import { Page } from '@tinajs/tina'
import { fetchData } from '../api'
Page.define({
async onLoad () {
this.$loading.push()
try {
const data = await fetchData()
// ...balabala
} catch () {}
this.$loading.pop()
},
})
Each time calling
$loading.push()
method should come with one$loading.pop()
.
Or simply use $loading()
with Promise.prototype.finally
:
// pages/some-page.js
import { Page } from '@tinajs/tina'
import { fetchData } from '../api'
Page.define({
onLoad () {
fetchData()
.then((data) => {
// ...balabala
})
// trick here
.finally(this.$loading())
},
})
-
Returns:
Function
-
Details:
Just a short way to call
$loading.push()
and return$loading.pop
-
Details:
Shows the loading spinner on the navigator bar, and pushes a loading-request to the cached stack.
-
Details:
Pops a loading-request from the cached stack, and hides the loading spinner on the navigator bar if the cached stack is empty.
- Returns:
Boolean
MIT @ yelo