将数组元素传递给另一个组件

时间:2021-06-25 13:00:51

标签: javascript vue.js

下午好。 我想将 categoriesTitle 传递给后模板组件。 categoriesForTheTitle 数组中的每个元素。

我收到错误:
错误“类别标题”被分配了一个值,但从未使用过 no-unused-var。

请告诉我我做错了什么?

<template >
  <v-container my-5 style="background: #eceef2">
    <post-template :categorieTitle="categorieTitle">
    </post-template>
  </v-container>
</template>

<script>
import { HTTP } from "../../http-common";

let categorieTitle;

let categoriesForTheTitle = [
  "business",
  "entertainment",
  "general",
  "health",
  "science",
  "sports",
  "technology",
];

for (var i = 0; i < categoriesForTheTitle .length; i++) {
  categorieTitle = categoriesForTheTitle[i];
}

export default {
 
};
</script>

<style>
</style>

2 个答案:

答案 0 :(得分:0)

错误的描述会告诉您您做错了什么:您为 categoryTitle 分配了一个值,但您从未对它做任何事情。您只需为它分配数组中的每个值,然后脚本结束。

答案 1 :(得分:0)

谢谢!我想到了。所需要的只是添加“返回”

export default {
data () {
return {
categorieTitle,
};
},
相关问题