Vue中使用JSX語法


 

 

一 項目結構

 

 

 

二 App組件

 

<template>
  <div id="app">
    <fruit/>
  </div>
</template>

<script>
import "./components/Fruit.js";
export default {
  name: "App"
};
</script>

<style lang="scss">
</style>

 

三 Fruit組件

 

import Vue from "vue";
import Mongo from "./Mongo.vue";

Vue.component("fruit", {
  data() {
    return {
      kind: "大青芒",
      address: "雲南"
    };
  },
  render() {
    const { kind, address } = this;
    return (
      <Mongo kind={kind} address={address}>
        very delicious
      </Mongo>
    );
  }
});

 

四 芒果組件

 

<template>
    <div>
        <h2>芒果</h2>
        <slot/>
        <h6>{{kind}},{{address}}</h6>
    </div>
</template>
<script>
export default {
  name: "Mango",
  props: ["kind", "address"]
};
</script>

 

五 運行效果

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM