Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 69ecd02

Browse files
committed
feat: now, the vue router is optional
1 parent cb18c68 commit 69ecd02

6 files changed

Lines changed: 118 additions & 146 deletions

File tree

dist/main.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ export declare function usePush(): {
2222
export default function install(
2323
Vue: Vue,
2424
{ router, siteIdList, isDebug }: Partial<Options>
25-
): false | undefined
25+
): void

dist/vue-baidu-analytics.js

Lines changed: 9 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-baidu-analytics.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-baidu-analytics.min.js

Lines changed: 97 additions & 114 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-baidu-analytics.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,7 @@ export default function install(
4949
/**
5050
* 一些环境和参数的检查
5151
*/
52-
if (typeof document === 'undefined' || typeof window === 'undefined') {
53-
return false
54-
}
55-
56-
if (!router) {
57-
throw new Error(
58-
'[vue-baidu-analytics] Must pass a Vue-Router instance to vue-baidu-analytics.'
59-
)
60-
}
52+
if (typeof document === 'undefined' || typeof window === 'undefined') return
6153

6254
if (!siteIdList) {
6355
throw new Error(
@@ -95,11 +87,13 @@ export default function install(
9587
/**
9688
* 路由切换时执行PV上报
9789
*/
98-
router.afterEach(() => {
99-
// 获取要上报的链接(当前版本不需要拼接了)
100-
const PAGE_URL: string = window.location.href
90+
if (router) {
91+
router.afterEach(() => {
92+
// 获取要上报的链接(当前版本不需要拼接了)
93+
const PAGE_URL: string = window.location.href
10194

102-
// 上报数据
103-
pushBAIDU.pv(PAGE_URL)
104-
})
95+
// 上报数据
96+
pushBAIDU.pv(PAGE_URL)
97+
})
98+
}
10599
}

0 commit comments

Comments
 (0)