Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
157 views
in Technique[技术] by (71.8m points)

r - Templating components and vue composition api

I am starting to use the vue composition API which is great for data, api calls etc. It works perfectly and cleans up my code.

I am not starting to think can I use it to create components. Probably not massive components but modals or something like that. I have not seen any examples where the composition function (I extract them to external .js files) provides a render function and creates the html, slots etc on the component.

Is this possible and good practice?

This is what I have so far but it will not render

import { reactive,  ref, computed } from '@vue/composition-api';
import Vue from 'vue';
export default function test () {
  const myButton = Vue.component('button-counter', {
    data: function () {
      return {
        count: 0
      }
    },
    template: '<button>You clicked me {{ count }} times.</button>'
  })
  return {
    myButton
  };
}

In the component where I am trying to use it

  setup() {
    const { myButton } = useTest();
    return { myButton };
  },

function VueComponent (options) { this._init(options); }


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...