Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我如何避免变异,并在其他组件中修改相同的属性?_Javascript_Vue.js_Components - Fatal编程技术网

Javascript 我如何避免变异,并在其他组件中修改相同的属性?

Javascript 我如何避免变异,并在其他组件中修改相同的属性?,javascript,vue.js,components,Javascript,Vue.js,Components,我是一个新的Dev VUE.JS开发人员,阅读了很多关于“共享/传递”数据到其他组件的内容,但我觉得这些示例在我的组件中没有什么用处 Table.vue - Fetch API and populate a table. File.vue - Instance Table.vue and here I'm trying to override the component variable. 表: <template> <v-simple-table class=&q

我是一个新的Dev VUE.JS开发人员,阅读了很多关于“共享/传递”数据到其他组件的内容,但我觉得这些示例在我的组件中没有什么用处

Table.vue - Fetch API and populate a table.
File.vue -  Instance Table.vue and here I'm trying to override the component variable.
表:

<template>
    <v-simple-table class="mt-5" id="tableOs" dense >
      <thead>
        <tr>
          <th v-for="h in headers" v-bind:key="h.value">{{h.text}}</th>
        </tr>
      </thead>      
      <tbody>
        <tr v-for="item in items" v-bind:key="item.id">
            <td>{{item.id}}</td>
            <td>{{item.customer}}</td>
            <td>{{item.neighbor}}</td>
        </tr>
      </tbody>
    </v-simple-table>
</template>

<script>
  export default {
    data (){
      return{
        headers: [
          { text: 'Id', value: 'id' },
          { text: 'Name', value: 'customer' },
          { text: 'Neighbor', value: 'neighbor' }
        ],
        items: this.pitems,    
      }
    },
    props:{
      'pitems': []
    },
    async created(){      
        const res = await fetch(
          "http://localhost:5000/buscarx/3",
            {
              method:"GET"
            }
        );
        const data = await res.json()
        this.items = data
    }
}  
</script>

{{h.text}}
{{item.id}
{{item.customer}}
{{item.neighbor}}
导出默认值{
数据(){
返回{
标题:[
{文本:'Id',值:'Id'},
{文本:'Name',值:'customer'},
{text:'Neighbor',value:'Neighbor'}
],
项目:此.pitems,
}
},
道具:{
“pitems”:[]
},
异步创建(){
const res=等待取数(
"http://localhost:5000/buscarx/3",
{
方法:“获取”
}
);
const data=await res.json()
this.items=数据
}
}  
和my Files.vue

<template>
  <v-container
    id="dashboard"
    fluid
    tag="section"
  >
    <v-btn @click="modify()"> </btn>
    <TableOS />
  </v-container>
</template>

<script>
   export default {
    components:{
      Table: () => import('./components/Table')
    },
    methods:{
      modify(){
        console.log(this.item)
      }
    }
  }
</script>

导出默认值{
组成部分:{
表:()=>导入('./组件/表')
},
方法:{
修改(){
console.log(this.item)
}
}
}
任何人都可以为我提供帮助,建议使用此提取的最佳方法,并修改表中的数据,以便在将来使用过滤器?

您可以使用它将变量从一个组件传递到另一个组件。 例如,您需要在File.vue内的
创建的
钩子中获取项目数据。将提取的项目保存在
items
数组中。 然后,您可以通过
prop
将此
数组传递到Table.vue组件

Table.vue - Fetch API and populate a table.
File.vue -  Instance Table.vue and here I'm trying to override the component variable.
您可以修改、筛选、映射并执行File.vue中
数组的其他任务。更改将是被动的,并自动反映在Table.vue文件中

您还可以使用在组件之间共享变量。但是,在孩子和家长之间共享变量的情况下,就像您的情况一样,您不需要这样做。但是,如果组件之间的关系不是那么简单,或者它们不相关,则必须使用
vuex

将变量从一个组件传递到另一个组件。 例如,您需要在File.vue内的
创建的
钩子中获取项目数据。将提取的项目保存在
items
数组中。 然后,您可以通过
prop
将此
数组传递到Table.vue组件

Table.vue - Fetch API and populate a table.
File.vue -  Instance Table.vue and here I'm trying to override the component variable.
您可以修改、筛选、映射并执行File.vue中
数组的其他任务。更改将是被动的,并自动反映在Table.vue文件中

您还可以使用在组件之间共享变量。但是,在孩子和家长之间共享变量的情况下,就像您的情况一样,您不需要这样做。但是,如果组件之间的关系不是那么简单,或者它们不相关,则必须使用
vuex