|
2 | 2 |
|
3 | 3 | Web renderer for weex project. Support Vue 2.x syntax.
|
4 | 4 |
|
| 5 | +[](https://travis-ci.org/weexteam/weex-vue-render) |
| 6 | +[](https://img.shields.io/badge/vue-2.x-brightgreen.svg) |
| 7 | +[](https://npmjs.com/package/weex-vue-render) |
| 8 | +[](https://npmjs.com/package/weex-vue-render) |
| 9 | +[](http://packagequality.com/#?package=weex-vue-render) |
| 10 | + |
5 | 11 | ## How To Use
|
6 | 12 |
|
7 | 13 | We strongly suggest you use v1.x instead of 0.12.x, according to performance issue.
|
@@ -120,125 +126,14 @@ You should use the previous mentioned plugins in your vue-loader configuration.
|
120 | 126 | | **exclusive styles** | limit | none | wirte them in `<style>` tag for better performance. |
|
121 | 127 | | | image attr: 'resize' | none | due to involving style changing, the 'resize' attribute shouldn't be a attribute binding like `:resize="someVar"`, instead you should use static attribute like `resize="cover"`. In other words, it shouldn't be updated. |
|
122 | 128 | | **ref** | what `this.$refs.xx` will get | always instance of VueComponent | HTMLElement for div, image and text; VueComponent for other components. |
|
123 |
| -# weex-vue-render |
124 |
| - |
125 |
| -Web renderer for weex project. Support Vue 2.x syntax. |
126 | 129 |
|
127 |
| -## How To Use |
128 |
| - |
129 |
| -We strongly suggest you use v1.x instead of 0.12.x, according to performance issue. |
| 130 | +## Develop |
130 | 131 |
|
131 | 132 | ```shell
|
132 |
| -npm install weex-vue-render |
133 |
| -``` |
134 |
| - |
135 |
| -```javascript |
136 |
| -// import vue runtime. |
137 |
| -const Vue = require('vue/dist/vue.runtime.common').default |
138 |
| -// import weex-vue-render |
139 |
| -const weex = require('weex-vue-render') |
140 |
| -// init the weex instance. |
141 |
| -weex.init(Vue) |
142 |
| -// import your .vue App. |
143 |
| -const App = require('App.vue') |
144 |
| -// must have a '#root' element in your html body. |
145 |
| -App.$el = '#root' |
146 |
| -// instantiate |
147 |
| -new App() |
148 |
| -``` |
149 |
| - |
150 |
| -> If import the UMD formated bundle to the html, then you dont't have to call `init` manually. |
151 |
| -
|
152 |
| -```html |
153 |
| -<script>{{Vue runtime}}</script> |
154 |
| -<script>{{weex-vue-render}}</script> |
155 |
| -<script>{{your web.bundle.js}}</script> |
| 133 | +# build for weex-vue-render package |
| 134 | +npm run build |
| 135 | +# debug and serve examples |
| 136 | +npm run dev |
| 137 | +# build and run test cases |
| 138 | +npm run test |
156 | 139 | ```
|
157 |
| - |
158 |
| -### pack your .vue file to web.bundle.js |
159 |
| - |
160 |
| -> You should pack your web.bundle.js and native.bundle.js separately. Use weex-loader for native packing and use vue-loader for web packing. |
161 |
| -
|
162 |
| -Use [vue-loader](https://github.com/vuejs/vue-loader) to pack your code for web.bundle.js. |
163 |
| - |
164 |
| -If you are using weex-vue-render@**1.x** , You should definitely use below plugins to get things work: |
165 |
| - |
166 |
| -* weex-vue-precompiler |
167 |
| -* autoprefixer |
168 |
| -* postcss-plugin-weex |
169 |
| -* postcss-plugin-px2rem |
170 |
| - |
171 |
| -> We use weex-vue-precompiler instead of `$processStyle` in 1.x verison. |
172 |
| -
|
173 |
| -Now, how to use this plugins to pack you web.bundle.js ? We use them in the vue-loader option. |
174 |
| - |
175 |
| -Here is a vue-loader option example: |
176 |
| - |
177 |
| -```javascript |
178 |
| -{ // webpack config. |
179 |
| - vue: { |
180 |
| - optimizeSSR: false, |
181 |
| - postcss: [ |
182 |
| - // to convert weex exclusive styles. |
183 |
| - require('postcss-plugin-weex')(), |
184 |
| - require('autoprefixer')({ |
185 |
| - browsers: ['> 0.1%', 'ios >= 8', 'not ie < 12'] |
186 |
| - }), |
187 |
| - require('postcss-plugin-px2rem')({ |
188 |
| - // base on 750px standard. |
189 |
| - rootValue: 75, |
190 |
| - // to leave 1px alone. |
191 |
| - minPixelValue: 1.01 |
192 |
| - }) |
193 |
| - ], |
194 |
| - compilerModules: [ |
195 |
| - { |
196 |
| - postTransformNode: el => { |
197 |
| - // to convert vnode for weex components. |
198 |
| - require('weex-vue-precompiler')()(el) |
199 |
| - } |
200 |
| - } |
201 |
| - ] |
202 |
| - } |
203 |
| -} |
204 |
| -``` |
205 |
| - |
206 |
| -> You should use a .js file as your webpack entry, not the Main.vue or App.vue file. |
207 |
| -
|
208 |
| -The content of your entry file `main.js` should be like this: |
209 |
| - |
210 |
| -```javascript |
211 |
| -// import Vue runtime if you like. |
212 |
| -// import weex-vue-render if you like. |
213 |
| -// init weex if you imported it. |
214 |
| -// at least it should have this: |
215 |
| -import App from './your/App.vue' |
216 |
| -App.el = '#root' |
217 |
| -new Vue(App) |
218 |
| -``` |
219 |
| - |
220 |
| -## How to Migrate from 0.12.x to 1.x |
221 |
| - |
222 |
| -> Why should I update to 1.x ? |
223 |
| -
|
224 |
| -The answer is **enoumouse change in rendering performance** with a few minor updates in your code is definitely worth to try. |
225 |
| - |
226 |
| -### packing configuration |
227 |
| - |
228 |
| -You should use the previous mentioned plugins in your vue-loader configuration. |
229 |
| - |
230 |
| -### check your code |
231 |
| - |
232 |
| -| category | rules | 0.12.x | 1.x | |
233 |
| -| --- | ---- | ------ | ----- | |
234 |
| -| **render function** | events binding | none | should add attrs as `data-evt-xxevent`. e.g. If binding a `appear` listener, you should add `attrs: { 'data-evt-appear': '' }` to your render data. | |
235 |
| -| | `click` event | none | should bind `weex$tap` event on web platform, and `click` event in other platforms. | |
236 |
| -| | tag name | none | when you use `createElement` to create a `image` element, you should create a `figure` element in web platform. With `text` you should use `p`. | |
237 |
| -| | attribute `src` for `img` | none | when you `createElement`, use a extra attr `data-img-src` for `figure` element, value of which is exactly the same as value of `src`. | |
238 |
| -| **styles** | style binding | none | better performance for binding object literal like `:style="{width:w,height:h}"` instead of object variable like `:style="someObj"` | |
239 |
| -| | styles in `animation.transition` | none | should add css prefix manualy if needed. We suggest you use [transition](https://weex-project.io/references/common-style.html#transition-v0-16-0) to implement animation. | |
240 |
| -| **events** | to emit a click event | just $emit a click event | you should $emit `weex$tap` event on web platform. | |
241 |
| -| | to emit a scroll event | just $emit a scroll event | you should $emit `weex$scroll` event on web platform. | |
242 |
| -| **exclusive styles** | limit | none | wirte them in `<style>` tag for better performance. | |
243 |
| -| | image attr: 'resize' | none | due to involving style changing, the 'resize' attribute shouldn't be a attribute binding like `:resize="someVar"`, instead you should use static attribute like `resize="cover"`. In other words, it shouldn't be updated. | |
244 |
| -| **ref** | what `this.$refs.xx` will get | always instance of VueComponent | HTMLElement for div, image and text; VueComponent for other components. | |
0 commit comments