Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

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

vue 怎么在列表list组件初始化(被渲染)时给它传递所需要的值

是否有初始化相关事件或者方法可以使用?
列表有若干条目,这些由一个数组传入。我想在这个组件被渲染时,把这个数组传入,能够把这些条目都渲染出来。

<div>
    <p id="proPanelTitle" class="proPanelSeparate">属性面板</p>
    <div class="proPanelSeparate">
        <p class="proPanelTitle2">组件名:</p>
        <p id="compName"></p>
    </div>
    <div id="proPanelContent1" >
        <div class="proPanelSeparate">
            <p><span class="proPanelTitle2">行:</span><input class="proPanelInput" type="number" value="4"/></p>
            <p><span class="proPanelTitle2">列:</span><input class="proPanelInput" type="number" value="4"/></p>
        </div>
        <div class="proPanelSeparate" >
            <p class="proPanelTitle2">单元格设置</p>
            <button class="proPanelBtn">合并单元格</button>
            <button class="proPanelBtn">拆分单元格</button>
            <select-custom id="select1" defaultStr="设置单元格" ></select-custom>
            <select-custom id="select2" defaultStr="设置表头"  ></select-custom>

        </div>
    </div>
    <div id="proPanelContent2" style="display: none;">
        <div class="proPanelSeparate">
            测试
        </div>
        <div class="proPanelSeparate" >
            测试
        </div>
    </div>
</div>

<select-custom id="select1" defaultStr="设置单元格" ></select-custom>
<select-custom id="select2" defaultStr="设置表头" ></select-custom>

这两行就是我的组件调用,我想用在他们被渲染时,把他们的列表内容Array传递进去。使其具有条目。但是我没查到有这方面的事件或者方法,能够获取这个时机。

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

1 Answer

0 votes
by (71.8m points)
<template>
    <div>
        {{formdata}}    
      </div>
</template>

<script>
export default {
  mounted(){
          this.initdata();
  },
  data () {
    return {
        formdata:"",  //声明
    }
  },
  methods:{
          initdata(){
              // ... 获取数据data 
              this.formdata=data;   //赋值
          }
  }
}
</script>

initdata用于初始化你的list组件数据,然后将initdata方法放在mounted中执行 (Vue1.0放在data就可以了)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...