按需引入

  1. <template>
  2. <view class="index">
  3. <view class="index">
  4. <AtNoticebar marquee>
  5. 欢迎使用 Taro UI Vue
  6. </AtNoticebar>
  7. <AtButton type="primary" :on-click="handleClick">
  8. AtButton
  9. </AtButton>
  10. <AtToast :is-opened="show" :text="msg" :on-close="handleClose"></AtToast>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. // 按需引入, 更小的应用体积
  16. import { AtButton, AtToast, AtNoticebar } from 'taro-ui-vue'
  17. import "taro-ui-vue/dist/style/components/button.scss"
  18. import "taro-ui-vue/dist/style/components/toast.scss"
  19. import "taro-ui-vue/dist/style/components/noticebar.scss"
  20. import './index.scss'
  21. export default {
  22. components: {
  23. AtButton,
  24. AtToast,
  25. AtNoticebar
  26. },
  27. data () {
  28. return {
  29. msg: 'Hello world!',
  30. show: false
  31. }
  32. },
  33. methods: {
  34. handleClick () {
  35. this.show = true
  36. },
  37. handleClose () {
  38. this.show = false
  39. }
  40. },
  41. }
  42. </script>

全局引入

import Vue from 'vue'
import './app.scss'
import 'taro-ui-vue/dist/style/index.scss'
import TaroUi from 'taro-ui-vue'
Vue.use(TaroUi)
const App = {
  onShow (options) {
  },
  render(h) {
    // this.$slots.default 是将要会渲染的页面
    return h('block', this.$slots.default)
  }
}

export default App