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

Commit e769d8e

Browse files
committed
update demo.
1 parent 61cdab4 commit e769d8e

File tree

13 files changed

+347
-138
lines changed

13 files changed

+347
-138
lines changed

demo/css/style.css

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#app,
2+
.section {
3+
display: flex;
4+
flex-direction: column;
5+
justify-content: flex-start;
6+
align-items: center;
7+
}
8+
.section {
9+
margin-bottom: 40px;
10+
}
11+
.title {
12+
font-size: 40px;
13+
color: #000;
14+
}
15+
.link {
16+
color: #666;
17+
text-decoration: none;
18+
}
19+
.link:hover {
20+
color: #000;
21+
}
22+
.nav {
23+
margin-bottom: 20px;
24+
}
25+
.nav .item {
26+
color: #666;
27+
margin: 0 10px 20px;
28+
}
29+
.nav .cur {
30+
color: #000;
31+
font-weight: bold;
32+
}
33+
.label {
34+
display: flex;
35+
justify-content: center;
36+
align-items: center;
37+
margin-bottom: 20px;
38+
}
39+
.text {
40+
display: flex;
41+
justify-content: flex-end;
42+
align-items: center;
43+
width: 60px;
44+
font-size: 14px;
45+
color: #333;
46+
margin-right: 20px;
47+
}
48+
.input {
49+
display: flex;
50+
align-items: center;
51+
width: 240px;
52+
height: 40px;
53+
font-size: 14px;
54+
box-sizing: border-box;
55+
padding: 0 10px;
56+
}
57+
.button {
58+
padding: 5px 20px;
59+
cursor: pointer;
60+
}

demo/js/main-for-vue2.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* 初始化路由
3+
* routes是来自 js/routes.js 里面的配置
4+
*/
5+
const router = new VueRouter({
6+
routes,
7+
linkActiveClass: 'cur',
8+
linkExactActiveClass: 'cur'
9+
});
10+
11+
12+
/**
13+
* 引入统计插件
14+
*/
15+
Vue.use(cnzzAnalytics, {
16+
router: router,
17+
siteIdList: [
18+
11111,
19+
22222,
20+
33333
21+
],
22+
isDebug: true
23+
});
24+
25+
26+
/**
27+
* 初始化Vue
28+
*/
29+
const app = new Vue({
30+
el: '#app',
31+
router,
32+
data () {
33+
return {
34+
pageUrl: '',
35+
category: '',
36+
action: '',
37+
label: '',
38+
value: ''
39+
}
40+
},
41+
mounted () {
42+
},
43+
methods: {
44+
pv () {
45+
this.$pushCNZZ.pv(this.pageUrl);
46+
},
47+
event () {
48+
this.$pushCNZZ.event(
49+
this.category,
50+
this.action,
51+
this.label,
52+
this.value
53+
);
54+
}
55+
}
56+
});

demo/js/main-for-vue3.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* 导入需要用到的组件
3+
*/
4+
const { createRouter, createWebHashHistory } = VueRouter;
5+
const { createApp, getCurrentInstance, ref } = Vue;
6+
7+
8+
/**
9+
* 初始化路由
10+
* routes是来自 js/routes.js 里面的配置
11+
*/
12+
const router = createRouter({
13+
history: createWebHashHistory(),
14+
routes,
15+
linkActiveClass: 'cur',
16+
linkExactActiveClass: 'cur'
17+
});
18+
19+
20+
/**
21+
* 创建实例
22+
*/
23+
const app = {
24+
setup () {
25+
// 插件要用到的一个代理组件
26+
const { proxy } = getCurrentInstance();
27+
28+
// 初始化要用到的数据
29+
const pageUrl = ref('');
30+
const category = ref('');
31+
const action = ref('');
32+
const label = ref('');
33+
const value = ref('');
34+
35+
// 提交pv的操作
36+
const pv = () => {
37+
proxy.$pushCNZZ.pv(pageUrl.value);
38+
}
39+
40+
// 提交事件的操作
41+
const event = () => {
42+
proxy.$pushCNZZ.event(
43+
category.value,
44+
action.value,
45+
label.value,
46+
value.value
47+
);
48+
}
49+
50+
// Vue 3.0 需要把模板要用到的东西 return 出去
51+
return {
52+
// 数据
53+
pageUrl,
54+
category,
55+
action,
56+
label,
57+
value,
58+
59+
// 方法
60+
pv,
61+
event
62+
}
63+
}
64+
};
65+
66+
67+
/**
68+
* 初始化Vue
69+
*/
70+
createApp(app)
71+
// 启动路由
72+
.use(router)
73+
74+
// 启动插件
75+
.use(cnzzAnalytics, {
76+
router: router,
77+
siteIdList: [
78+
11111,
79+
22222,
80+
33333
81+
],
82+
isDebug: true
83+
})
84+
85+
// 挂载到节点上
86+
.mount('#app');

demo/js/main.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

demo/js/routes.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* 定义路由信息
3+
*/
4+
const routes = [
5+
{
6+
path: '/',
7+
redirect: '/page1'
8+
},
9+
{
10+
path: '/page1',
11+
component: {
12+
template: '<div class="view">当前是 <strong>Page1</strong> 的路由</div>'
13+
}
14+
},
15+
{
16+
path: '/page2',
17+
component: {
18+
template: '<div class="view">当前是 <strong>Page2</strong> 的路由</div>'
19+
}
20+
},
21+
{
22+
path: '/page3',
23+
component: {
24+
template: '<div class="view">当前是 <strong>Page3</strong> 的路由</div>'
25+
}
26+
}
27+
];

0 commit comments

Comments
 (0)