Skip to content

Commit 42c153f

Browse files
author
zhigang.li
committed
在动态路由匹配和带参路由匹配页面增加closeTag关闭页面示例
1 parent 3ec36b6 commit 42c153f

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/view/argu-page/params.vue

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,32 @@
22
<div>
33
<Card>
44
<h2>ID: {{ $route.params.id }}</h2>
5+
<Button @click="close">调用closeTag方法关闭本页</Button>
56
</Card>
67
</div>
78
</template>
89

910
<script>
11+
import { mapMutations } from 'vuex'
1012
export default {
11-
name: 'argu_page'
13+
name: 'params',
14+
methods: {
15+
...mapMutations([
16+
'closeTag'
17+
]),
18+
close () {
19+
/**
20+
* 如果是调用closeTag方法,普通的页面传入的对象参数只需要写name字段即可
21+
* 如果是动态路由和带参路由,需要传入query或params字段,用来区别关闭的是参数为多少的页面
22+
*/
23+
this.closeTag({
24+
name: 'params',
25+
params: {
26+
id: this.$route.params.id
27+
}
28+
})
29+
}
30+
}
1231
}
1332
</script>
1433

src/view/argu-page/query.vue

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,32 @@
22
<div>
33
<Card>
44
<h2>ID: {{ $route.query.id }}</h2>
5+
<Button @click="close">调用closeTag方法关闭本页</Button>
56
</Card>
67
</div>
78
</template>
89

910
<script>
11+
import { mapMutations } from 'vuex'
1012
export default {
11-
name: 'query'
13+
name: 'query',
14+
methods: {
15+
...mapMutations([
16+
'closeTag'
17+
]),
18+
close () {
19+
/**
20+
* 如果是调用closeTag方法,普通的页面传入的对象参数只需要写name字段即可
21+
* 如果是动态路由和带参路由,需要传入query或params字段,用来区别关闭的是参数为多少的页面
22+
*/
23+
this.closeTag({
24+
name: 'query',
25+
query: {
26+
id: this.$route.query.id
27+
}
28+
})
29+
}
30+
}
1231
}
1332
</script>
1433

0 commit comments

Comments
 (0)