模极社社区 - 制造业全产业链交流平台

    • 登录
    • 版块
    • 最新
    • 话题
    • 热门
    • 用户
    • 群组

    Babel Plugin JSX for Vue——模具行业从业者必备知识手册

    社区公告
    1
    1
    0
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • S
      system 2 最后由 编辑

      <h2>Babel Plugin JSX for Vue 3</h2>

      <p><a href="upload://7HmiCTQxfywL7x6pbT8XcgAF33G.svg"><img src="https://www.npmjs.com/package/@vue/babel-plugin-jsx" alt="npm package</a>"></p>
      <p><a href="upload://eK0sHoCe7JRbEIqWrYtIN1f7JaM.svg"><img src="https://github.com/actions-cool/issues-helper" alt="issues-helper</a>"></p>

      <p>To add Vue JSX support.</p>

      <p>English | <a href="/packages/babel-plugin-jsx/README-zh_CN.md">简体中文</a></p>

      <h3>Installation</h3>

      <p>Install the plugin with:</p>

      <pre><code>
      npm install @vue/babel-plugin-jsx -D
      </code></pre>

      <p>Then add the plugin to your babel config:</p>

      <pre><code>
      {
      "plugins": ["@vue/babel-plugin-jsx"]
      }
      </code></pre>

      <h3>Usage</h3>

      <h4>options</h4>

      <p>#### transformOn</p>

      <p>Type: <code>boolean</code></p>

      <p>Default: <code>false</code></p>

      <p>transform <code>on: { click: xx }</code> to <code>onClick: xxx</code></p>

      <p>#### optimize</p>

      <p>Type: <code>boolean</code></p>

      <p>Default: <code>false</code></p>

      <p>When enabled, this plugin generates optimized runtime code using <a href="https://vuejs.org/guide/extras/rendering-mechanism#patch-flags"><code>PatchFlags</code></a> and <a href="https://github.com/vuejs/core/blob/v3.5.13/packages/runtime-core/src/componentSlots.ts#L69-L77"><code>SlotFlags</code></a> to improve rendering performance. However, due to JSX's dynamic nature, the optimizations are not as comprehensive as those in Vue's official template compiler.</p>

      <p>Since the optimized code may skip certain re-renders to improve performance, we strongly recommend thorough testing of your application after enabling this option to ensure everything works as expected.</p>

      <p>#### isCustomElement</p>

      <p>Type: <code>(tag: string) => boolean</code></p>

      <p>Default: <code>undefined</code></p>

      <p>configuring custom elements</p>

      <p>#### mergeProps</p>

      <p>Type: <code>boolean</code></p>

      <p>Default: <code>true</code></p>

      <p>merge static and dynamic class / style attributes / onXXX handlers</p>

      <p>#### enableObjectSlots</p>

      <p>Type: <code>boolean</code></p>

      <p>Default: <code>true</code></p>

      <p>Whether to enable <code>object slots</code> (mentioned below the document) syntax". It might be useful in JSX, but it will add a lot of <code>_isSlot</code> condition expressions which increase your bundle size. And <code>v-slots</code> is still available even if <code>enableObjectSlots</code> is turned off.</p>

      <p>#### pragma</p>

      <p>Type: <code>string</code></p>

      <p>Default: <code>createVNode</code></p>

      <p>Replace the function used when compiling JSX expressions.</p>

      <p>#### resolveType</p>

      <p>Type: <code>boolean</code></p>

      <p>Default: <code>false</code></p>

      <p>(<strong>Experimental</strong>) Infer component metadata from types (e.g. <code>props</code>, <code>emits</code>, <code>name</code>). This is an experimental feature and may not work in all cases.</p>

      <h3>Syntax</h3>

      <h4>Content</h4>

      <p>functional component</p>

      <pre><code>
      const App = () => <div>Vue 3.0</div>;
      </code></pre>

      <p>with render</p>

      <pre><code>
      const App = {
      render() {
      return <div>Vue 3.0</div>;
      },
      };
      </code></pre>

      <pre><code>
      import { withModifiers, defineComponent } from 'vue';

      const App = defineComponent({
      setup() {
      const count = ref(0);

      const inc = () => {
        count.value++;
      };
      
      return () => (
        <div onClick={withModifiers(inc, ['self'])}>{count.value}</div>
      );
      

      },
      });
      </code></pre>

      <p>Fragment</p>

      <pre><code>
      const App = () => (
      <>
      <span>I'm</span>
      <span>Fragment</span>
      </>
      );
      </code></pre>

      <h4>Attributes / Props</h4>

      <pre><code>
      const App = () => <input type="email" />;
      </code></pre>

      <p>with a dynamic binding:</p>

      <pre><code>
      const placeholderText = 'email';
      const App = () => <input type="email" placeholder={placeholderText} />;
      </code></pre>

      <h4>Directives</h4>

      <p>#### v-show</p>

      <pre><code>
      const App = {
      data() {
      return { visible: true };
      },
      render() {
      return <input v-show={this.visible} />;
      },
      };
      </code></pre>

      <p>#### v-model</p>

      <blockquote>
      <p>Note: You should pass the second param as string for using <code>arg</code>.</p>
      </blockquote>

      <pre><code>
      <input v-model={val} />
      </code></pre>

      <pre><code>
      <input v-model:argument={val} />
      </code></pre>

      <pre><code>
      <input v-model={[val, ['modifier']]} />
      // Or
      <input v-model_modifier={val} />
      </code></pre>

      <pre><code>
      <A v-model={[val, 'argument', ['modifier']]} />
      // Or
      <input v-model:ar


      踩过坑的来评论区说说。
      </code></pre>

      1 条回复 最后回复 回复 引用 0
      • First post
        Last post
      Powered by NodeBB | Contributors