一个容器里面有多个组件输入框,点击个数,遍历出相同的容器,要让每个容器绑定的值不同
不知道你这个问题是否已经解决, 如果还没有解决的话:在全局中定义好方法以后去页面中调用此方法
async onLoad(e) {
// 页面中执行这个请求方法 也可以传值URL链址
await this.$visitStore();//同步执行这个方法
}
请求方法成功后,在异步请求的成功回调后执行store.commit('systeminfo',res)
,就是将获取到的数据赋值到vuex。
containerValues
。v-for
指令在父组件中渲染多个容器组件,并使用v-model
指令将每个容器的值与containerValues
中的对应项进行绑定。inputValue
,作为当前容器的输入框的值。v-model
指令将输入框的值与inputValue
进行绑定。selectedContainerIndex
。selectedContainerIndex
来访问containerValues
中对应索引的值,即可获取到所选容器的值。以下是一个简单的示例代码:
<!-- 父组件 -->
<template>
<div>
<div v-for="(container, index) in containers" :key="index">
<child-component v-model="containerValues[index]"></child-component>
</div>
<button @click="getSelectedContainerValues">获取选中容器的值</button>
</div>
</template>
<script>
import ChildComponent from './ChildComponent.vue';
export default {
components: {
ChildComponent,
},
data() {
return {
containers: [1, 2, 3], // 假设有三个容器
containerValues: [], // 用于存储每个容器的值
selectedContainerIndex: 0, // 被选中的容器索引
};
},
methods: {
getSelectedContainerValues() {
const selectedContainerValue = this.containerValues[this.selectedContainerIndex];
console.log('选中容器的值:', selectedContainerValue);
},
},
};
</script>
<!-- 子组件 -->
<template>
<div>
<input type="text" v-model="inputValue">
</div>
</template>
<script>
export default {
data() {
return {
inputValue: '',
};
},
};
</script>
在上述示例中,父组件中的containers数组存储了三个容器的信息,containerValues数组用于存储每个容器的值。通过v-for指令渲染了三个子组件,并使用v-model指令将每个容器的值与containerValues中对应索引的项进行绑定。在子组件中,定义了inputValue作为当前容器的输入框的值,通过v-model指令与输入框进行绑定。在父组件中,通过点击事件获取到要遍历的容器的索引selectedContainerIndex,并根据索引访问containerValues数组,从而获取到所选容器的值。
这样就实现了动态表单分页显示,并且每个容器绑定的值都是不同的。希望对你有帮助!如有需要,请随时提问。