javascript - 使用 Vue 渲染时加载相同的两个页面
问题描述
当我在搜索中添加一些文本并单击按钮以呈现搜索结果的新视图时,我得到两个相同的页面。例如,当我输入 时AMZN
,我会转到stocks/AMZN
页面,但是当我按“返回”时,stocks/AMZN
会加载相同的页面。当我再次单击“返回”时,我回到了我的初始页面。
我怎样才能只渲染一页?
我正在使用 Vue,这是我的代码。
下面是我的 .vue 文件的脚本部分。
data() {
return {
tickerSymbol: null,
stock: {},
summaryReadMore: false,
};
},
created() {
this.fetchProfile();
},
methods: {
fetchProfile() {
this.tickerSymbol = this.$route.params.symbol;
axios.get(`${import.meta.env.VITE_SBT_PERFORMANCE_SERVICE_URL}/stocks/${this.tickerSymbol}`)
.then(resp => {
this.stock = resp.data;
});
},
redirectToNewProfile() {
this.$router.push({ name: 'Stocks', params: {symbol: this.$refs.searchItem.value} })
},
下面是我的 .vue 文件的 html 部分:
<form v-on:submit="redirectToNewProfile()">
<div class="shadow flex">
<input class="w-full rounded p-2" type="text" placeholder="Search..." ref="searchItem"
v-on:keyup.enter.prevent="redirectToNewProfile()">
<button class="bg-white w-auto flex justify-end items-center text-blue-500 p-2 hover:text-blue-400">
<i class="material-icons">search</i>
</button>
</div>
</form>
解决方案
推荐阅读
- powershell - 在powershell中更改终端宽度时如何运行函数
- amazon-web-services - Amazon Cognito 用户池 - 设置用户 + 角色 + 权限
- database - MongoDB分片集群,平衡器关闭时的行为?
- amazon-web-services - AWS + Cloudflare | https 被重定向到 http
- python - Django Admin,ValidationError as flash?
- r - 在 r 中:选择具有预定义差异的案例对
- python - 在 Python 中异步编写 CSV 文件
- html - 当视口通过实用程序类达到一定宽度时,缩小引导按钮和输入字段的大小
- google-chrome - 从 chrome 扩展获取所有在 chrome 浏览器上登录的帐户
- spring-webflux - Spring Data Reactive R2DBC 分页