javascript - 当我在 Vue 中单击路由页面 About 时,数据正在清除
问题描述
请帮帮我!我有两个页面:Home
和About
一个组件SecondPage
。该组件有两个带有数据的表格,它应该显示在About
页面上。但是当我导航到About
页面时,所有数据都被清除,表格为空。我试图将About
页面中的所有内容作为About
组件显示在我的主页Home
中,并且它有效!所以,道具是正确传递的。About
为什么当我单击它时,表中的所有数据都消失在页面中?我试过.prevent
了,但它没有按我的预期工作。
关于.vue
<template>
<div class="about">
<h1>This is an about page</h1>
<SecondPage v-bind:generalQuestInfo="generalQuestInfo" :isActive="isActive" :getIconClass="getIconClass" />
</div>
</template>
<script>
import SecondPage from '../components/SecondPage'
export default {
name: 'About',
components: {
SecondPage
},
props: ["generalQuestInfo", "isActive", "getIconClass"]
}
</script>
家
<template>
<div id="app">
<h1>Quest Statistics</h1>
<MainPage v-bind:mainPageInfo="mainPageInfo" v-on:main-handle="handler(loadGeneralQuestInfo, loadFinishedQuestleafs, $event)" />
<SecondPage v-bind:generalQuestInfo="generalQuestInfo" :isActive="isActive" :getIconClass="getIconClass"/>
<About v-bind:generalQuestInfo="generalQuestInfo" :isActive="isActive" :getIconClass="getIconClass"/>
</div>
</template>
<script>
import MainPage from '../components/MainPage'
import SecondPage from '../components/SecondPage'
import About from './About'
import axios from 'axios'
export default {
name: 'Home',
components: {
MainPage,
SecondPage,
About
},
data(){
return {
mainPageInfo: [],
generalQuestInfo: [],
finishedQuestleafs: [],
isActive: 0 //this value is changing according to icon that was clicked in table from MainTable.vue
}
},
第二页
<template>
<div>
//two tables are here
</div>
</template>
<script>
export default {
name: "SecondPage",
props: ["generalQuestInfo", "isActive", "getIconClass"]
}
添加另一段代码。当点击图标时,它会打开About
带有表格的页面。但是表是空的,看起来重定向是在道具传递给子组件之前发生的???页面未重新加载
主页
<template>
<div>
<table align="center">
<tr>
<th v-bind:key="data.id" v-for="data in mainPageInfo">{{ data.alias }}</th>
</tr>
<tr>
<td v-bind:key="data.id" v-for="data in mainPageInfo">
<router-link :to="data.status == 'SUCCESS' || data.status == 'CRASH' ? '/about' : '/no-info'"><i v-on:click="$emit('main-handle', data.status)" v-bind:class="data.status == 'SUCCESS' ? 'fas fa-check':
data.status == 'CRASH' ? 'fas fa-times' :
'fas fa-minus'"></i></router-link>
</td>
</tr>
</table>
</div>
</template>
解决方案
Vue 文档表明Prop Cases (camelCase vs kebab-case)
HTML 属性名称不区分大小写,因此浏览器会将任何大写字符解释为小写。这意味着当您使用 in-DOM 模板时,camelCased 道具名称需要使用它们的 kebab 大小写(连字符分隔)等效项:
然后,当你在他的 HTML 模板中调用某个组件时,你应该在 kebab-case 中编写 prop:
<!-- kebab-case in HTML -->
<blog-post post-title="hello!"></blog-post>
在你的组件上,你必须在 camelCase 中调用你的道具:
Vue.component('blog-post', {
// camelCase in JavaScript
props: ['postTitle'],
template: '<h3>{{ postTitle }}</h3>'
})
推荐阅读
- bash - 如何将环境变量从 WSL 传递到 Windows 可执行文件
- windows - 在 cmd 中调用 dir 会打印出:“驱动器 C 中的卷没有标签。”
- vba - 数据表视图中的 MS Access 表单交叉表查询
- azure-devops - 多阶段 YAML Azure 管道变量范围
- filesystems - 是否可以从 Service Worker 使用 webkitRequestFileSystem?
- matlab - 为什么我的 GUI 中的 uitable 元素偶尔会在 MATLAB 中丢失?
- pyspark - 如何像在 SAS 中一样在 PySpark 中创建多列添加 if then do 语句(没有别的)?
- javascript - 来自 C# 的 Highcharts 范围选择器日期格式
- html - 无法在网页上获得等间距的边距
- linux - Android Studio 看不到 Chrome 设备