1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- Page({
- onShareAppMessage() {
- return {
- title: '动态加载字体',
- path: 'packageAPI/pages/media/load-font-face/load-font-face'
- }
- },
- data: {
- theme: 'light',
- fontFamily: 'Bitstream Vera Serif Bold',
- loaded: false,
- },
- onLoad() {
- this.setData({
- theme: wx.getSystemInfoSync().theme || 'light'
- })
- if (wx.onThemeChange) {
- wx.onThemeChange(({theme}) => {
- this.setData({theme})
- })
- }
- this.setData({
- loaded: false
- })
- },
- loadFontFace() {
- const self = this
- wx.loadFontFace({
- family: this.data.fontFamily,
- source: 'url("https://sungd.github.io/Pacifico.ttf")',
- success(res) {
- console.log(res.status)
- self.setData({loaded: true})
- },
- fail(res) {
- console.log(res.status)
- },
- complete(res) {
- console.log(res.status)
- }
- })
- },
- clear() {
- this.setData({loaded: false})
- },
- onLoad() {
- this.setData({
- theme: wx.getSystemInfoSync().theme || 'light'
- })
- if (wx.onThemeChange) {
- wx.onThemeChange(({theme}) => {
- this.setData({theme})
- })
- }
- }
- })
|