编辑器
Hbuilder
uniapp默认不支持sass,需安装插件
路由
路由需在pages.json中设置后方可使用
{
"pages": [{
"path": "pages/index/Home",
"style": {
"navigationBarTitleText": "主页"
}
}
],
"globalStyle": {
"navigationBarTextStyle": "white",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#007AFF",
"backgroundColor": "#FFFFFF"
}
}
在uniapp中使用iconfont
- 从iconfont上下载svg
- 将iconfont.css放入项目中
- 将@font-face改为iconfont上刷新得到的代码,并在每一行前加上https:
- 在需要的地方使用view标签,加上一个class,class名位你想用的那个标签
ui框架
ui框架推荐:uniui
DOM问题
在uniapp中,我们无法是获取到DOM元素的。
uniapp中使用vuex
- 创建store 根目录下创建 store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
import dayjs from "dayjs"
Vue.use(Vuex)
const store = new Vuex.Store({
state: {},
mutations: {},
}
)
export default store
- 在全局引用,并挂载到原型上
import Vue from 'vue'
import App from './App'
import store from "./store"
Vue.prototype.$store = store
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App,
store
})
app.$mount()
- 组件内可直接通过this.$store 使用
localStorage
uniapp不支持localStorage,可通过setStorage/getStorage代替
需注意,uniapp中有同步/异步之分
可视化
可视化可通过ucharts实现,但是需要微信开发中工具为2020/6以前版本,否则可能会报错
alert
uniapp不支持alert,有自己的api,如uni.showModal