【发布时间】:2021-03-16 07:45:18
【问题描述】:
我有一个这样的查询字符串:
https://someurl.com?q=test
我有一个像这样的组件:
Vue.component('externalrecipes', {
props: ['results'],
template: `
<section>
<div class="" v-for="result in results">
<div class="card card-similar card-external text-center">
<img :src="result.image_url" />
<div id="meta" class="text-center">
<h5>{{ result.title }}</h5>
<a target="_blank" :href="'https://www.wine-searcher.com/find/' + q + '/1/uk'" role="button">Buy Wine</a>
</div>
</div>
</div>
</section>
`
})
但是,这不起作用。我希望能够将查询字符串中 'q' 的值传递给这行代码:
<a target="_blank" :href="'https://www.wine-searcher.com/find/' + q + '/1/uk'" role="button">Buy Wine</a>
我该怎么做呢?
【问题讨论】:
-
你在用vue-router吗?
-
不,我不是,我的 vue 之旅还很早,我还没有接触到路由器。
-
似乎您必须在组件的上下文中通过道具或数据属性定义
q。 -
好的,我该怎么做?
-
在实例化组件时添加一个
q(或者可能是queryId)道具。或者您使用通过v-for指令定义的result项目的属性
标签: javascript vue.js query-string