weexteam / vue-framework-for-Apache-Weex

This repos is a third party work, and is not developed nor maintained by Apache Weex.
MIT License
295 stars 23 forks source link

Differences between using Vue in Web and Weex #11

Open Jinjiang opened 8 years ago

Jinjiang commented 8 years ago

In Weex you can write code with Vue, a progressive framework for building user interfaces. Also you can find some tools and resources by it.

So this introduction assumes you have knowledge of Vue in the web and know the syntax and usage of Vue.

Here are some notes differences about using Vue between Weex and web.

A "hello world" example in Weex is just below:

<template>
  <div>
    <text>{{ message }}</text>
  </div>
</template>
<script>
  export const data = {
    message: 'Hello Vue!'
  }
</script>

More informations you may need to know:

Something need to check in depth:

yyx990803 commented 8 years ago

A few extra things I noticed, if the user writes raw render functions by hand:

  1. Weex's class runtime module expects vnode.data.staticClass and vnode.data.class to be Arrays, but in Vue it can be a string, an Object OR an Array. To make sure a Vue component that uses render function can run in Weex, Weex's class runtime module needs to normalize these types into Arrays.

2. In Weex to create a text node in render functions we need to do h('text', { attrs: { value: 'Hello' }}) but in Vue you can just pass a string. Weex's createElement needs to be wrapped to normalize this. Seems to already be supported judging from the tests in node.spec.js

Jinjiang commented 8 years ago

In Weex to create a text node in render functions we need to do h('text', { attrs: { value: 'Hello' }}) but in Vue you can just pass a string. Weex's createElement needs to be wrapped to normalize this.

Text node is compatible now:

// { "framework": "Vue" }

new Vue({
  el: 'body',
  render: function(createElement) {
    return createElement('div', undefined, ['Hello'])
  }
})

It just works because we did some hacks in text content:

erguotou520 commented 7 years ago
  • Btw the native components Weex supports are not same to W3C HTML Tags. See more about this here.

Missing link for more about this here 😄

NoraGithub commented 7 years ago

Sometimes it occurs that,cannot find element root after building a vue file.( However, I cannot accurately describe when it would occur)

Do you have any suggestions about how to solve it?

34r7h commented 7 years ago

@NoraGithub i've added id="root" on the root elements of each component :/

NoraGithub commented 7 years ago

@irthos Thanks for your enthusiasm . I solved it by modify the webpack config.

All info is described by the commit/issue https://github.com/zwwill/yanxuan-weex-demo/pull/21

34r7h commented 6 years ago

@NoraGithub how did you modify webpack.config to allow global $router?