I made an app using Uniapp, but I feel that the performance is not very good. After learning about Nvue in Uniapp, I wanted to create a pure Nvue project. In fact, it's basically a Weex project. I have to say that there are really a lot of pitfalls, but the rendering performance is really unmatched.
The development environment for this project is a pure NVUE project in UNIAPP, which is different from WEEX.
https://github.com/WindrunnerMax/SW
Each node is automatically set to flex, so there is no need to declare it again, and flex is the only layout mode.
The default direction of flex is vertical, which is different from the default in web. You need to manually declare it as horizontal using flex-direction: row;.
Use align-items: center;justify-content: center;/* flex as an example of horizontal */ for center alignment.
Weex does not support the page selector, nor does it have page styles. Setting the backgroundColor in page.json also has no effect.
The only way to set the overall page color is to take a detour, but the effect is not particularly good.
Note that this is the Nvue method in Uniapp.
In addition, directly setting flex:1 in .page and assigning class="page" to the root node can expand the page to full screen, but it will also prevent the page from scrolling.
The official robot has provided a better solution.
Another pitfall is that Nvue does not support global components. Each page must import the components it needs separately.
/** First declare the .page class **/.page{font-family: Arial,,'STHeiti STXihei','Microsoft YaHei', Tohoma, sans-serif;padding: 10px;font-size: 15px;background-color: #F8F8F8;}
<template><view><viewclass="page"ref="box"><!-- Declare page and container block, pay attention to ref --><!-- Page content --></view><viewstyle="background-color: #F8F8F8;":style="pageFill"></view><!-- Fill block --></view></template>
// Get the height of the page that has been used, and set the height of the fill block to screen height minus the height of the used containerconst app =getApp()const dom = weex.requireModule('dom');exportdefault{data(){return{pageFill:{width:"750rpx",height:"0rpx"}}},onReady:function(){this.resize();// Call resize to adjust the size of the fill blockvar that =this;// In uni.requests, you can call that.$nextTick(() => { that.resize() }) in success},methods:{resize:function(){const that =this;const result = dom.getComponentRect(this.$refs.box,option=>{ that.pageFill.height =(uni.getSystemInfoSync().windowHeight - option.size.height)+'px'; console.log(uni.getSystemInfoSync().windowHeight, option.size.height);})},}}
<!-- In the case of using flex:1;, you can set the full-screen page, but the page will not be able to scroll --><!-- In the page --><template><viewclass="page"><!-- Node content --></view></template><!-- In App.vue --><style>.page{
font-family: Arial, Helvetica, 'STHeiti STXihei', 'Microsoft YaHei', Tohoma, sans-serif;
padding: 10px;
font-size: 15px;
flex: 1;
background-color: #F8F8F8;
}
</style>
<!-- Official method, accidentally saw the reply from the official group robot --><template><viewclass="page"style="flex:1;"><scroll-viewscroll-y="true"><view><!-- Page content --></view></scroll-view></view></template>
### 4. width width
- Weex supports px and wx as length units for length units, and does not support relative units (em, rem, pt, %)
- In Uniapp compilation mode, rpx is a dynamic unit based on a 750px wide screen, and px is a fixed pixel unit
- 750rpx is the full-screen benchmark of Nvue in Uniapp, which requires Uniapp as the compilation mode, different from Weex compilation mode
- Except for fixed-size images, etc., you can use flex to complete the layout, pay attention to use `flex:1;`
### 5. border border
```css
/** border does not support shorthand **/
/* Supported */
.border{
border-style: solid;
border-color: #EEEEEE;
border-bottom-width: 1px;
}
/* Not supported */
.border{
border: 1px solid #eee;
}
z-index is not supported for setting the level relationship, but the element at the back has a higher level, so you can place the element with a higher level at the back
/** background does not support shorthand. Shorthand can render colors normally in browsers, but colors cannot be rendered normally on mobile phones **//* Supported */.backgroundT{background-color: #F8F8F8;}/* Not supported */.backgroundT{background: #F8F8F8;}
/** Take Alibaba Vector Icon Library iconfont as an example to introduce font icons **//** Only need to import once on the homepage, all pages can be used **/
/* App.vue */.iconfont{font-family: iconfont;}
// Import on the application homepageconst dom = weex.requireModule('dom');dom.addRule('fontFace',{'fontFamily':'iconfont','src':"url('https://at.alicdn.com/t/font_1582902_mwrjy69s3lm.ttf')"})