新增:记录页面访问量 API,并修复部分错误
This commit is contained in:
@@ -25,5 +25,13 @@ export const head: HeadConfig[] = [
|
||||
hm.src = "https://hm.baidu.com/hm.js?53af4b1a12fbe40810ca7ad39f8db9c7";
|
||||
var s = document.getElementsByTagName("script")[0];
|
||||
s.parentNode.insertBefore(hm, s);
|
||||
})();`]
|
||||
})();`],
|
||||
// 页面访问量统计
|
||||
['script', {}, `var pageUrl = location.href;
|
||||
(function() {
|
||||
var pv = document.createElement("script");
|
||||
pv.src = "https://api.charles7c.top/blog/pv?pageUrl=" + pageUrl;
|
||||
var s = document.getElementsByTagName("script")[0];
|
||||
s.parentNode.insertBefore(pv, s);
|
||||
})();`],
|
||||
]
|
@@ -1,7 +1,7 @@
|
||||
import { request } from './config'
|
||||
|
||||
export const getPv = (id, call) => {
|
||||
request.get(`/pv/${id}`, {}).then(result => {
|
||||
export const getPv = (id, pageUrl, call) => {
|
||||
request.get(`/article/view/${id}?pageUrl=${pageUrl}`, {}).then(result => {
|
||||
call(process(result))
|
||||
})
|
||||
}
|
||||
|
@@ -82,7 +82,7 @@ const { author, authorLink, showPv, date, toDate, categories, tags, showCategory
|
||||
if (data.showPv) {
|
||||
// 记录并获取文章阅读数(使用文章标题 + 发布时间生成 MD5 值,作为文章的唯一标识)
|
||||
onMounted(() => {
|
||||
$api.getPv(md5(props.article.title + props.article.date), function(data) {
|
||||
$api.getPv(md5(props.article.title + props.article.date), location.href, function(data) {
|
||||
document.getElementById("pv").innerText = data
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user