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
291 views
in Technique[技术] by (71.8m points)

Vue组件使用问题

这是一个a.vue文件的部分代码

export default {
        name: 'lab',
        data(){
        ....

主js文件的代码

import lalala from './a.vue'
var vm = new Vue({
    el: '#app',
    data: {
      ...
    },
    render (h) {
        return h(lalala)
    }

该主js文件被index.html使用

请问name属性设置为lab意思是不是在index.html中使用<lab></lab>来使用这个a.vue组件?

我一开始是这样想的,但是结果a.vue组件还是把<div id='#app'>...</div>给整个替换了
请问如何实现我上述的想法


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

1 Answer

0 votes
by (71.8m points)

要实现组件调用,需要注册

import lab from './a.vue'

export default {
  name: 'test',
  components: {
    lab,
  }
<lab> </lab>

我对这个name的理解是递归组件用的


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

...