8
8
</div >
9
9
10
10
<script >
11
- const app = new Vue ({
12
- el: ' #app' ,
13
- data: {
14
- message: ' Hello Vue!' ,
15
- graphOptions: {
16
- defaultJunctionPoint: ' border'
17
- // 这里可以参考"Graph 图谱"中的参数进行设置
18
- }
19
- },
20
- mounted () {
21
- this .showRelationGraph ();
22
- },
23
- methods: {
24
- showRelationGraph () {
11
+ window .onload = function () {
12
+ initializeVueApp ();
13
+ };
14
+ function initializeVueApp () {
15
+ let app = new Vue ({
16
+ el: ' #app' ,
17
+ data: {
18
+ message: ' Hello Vue!' ,
19
+ graphOptions: {
20
+ defaultJunctionPoint: ' border'
21
+ // 这里可以参考"Graph 图谱"中的参数进行设置
22
+ }
23
+ },
24
+ mounted () {
25
+ this .showRelationGraph ();
26
+ },
27
+ methods: {
28
+ showRelationGraph () {
25
29
26
- debugger ;
27
- console .log (' ref:btn:' , this .$refs .btn );
28
- console .log (' ref:' , this .$refs .seeksRelationGraph );
29
- const url = new URL (window .location .href );
30
+ debugger ;
31
+ console .log (' ref:btn:' , this .$refs .btn );
32
+ console .log (' ref:' , this .$refs .seeksRelationGraph );
33
+ const url = new URL (window .location .href );
30
34
31
- // 获取查询字符串部分
32
- const queryString = url .search ;
35
+ // 获取查询字符串部分
36
+ const queryString = url .search ;
33
37
34
- // 解析查询字符串为一个 URLSearchParams 对象
35
- const urlParams = new URLSearchParams (queryString);
38
+ // 解析查询字符串为一个 URLSearchParams 对象
39
+ const urlParams = new URLSearchParams (queryString);
36
40
37
- // 获取参数的值,例如 'index'
38
- const index = urlParams .get (' index' );
39
- fetch (' /api/GraphDemo/GetAllGraphs?index=' + index)
40
- .then (response => {
41
- if (! response .ok ) {
42
- throw new Error (' 网络响应不成功,状态码:' + response .status );
43
- }
44
- return response .json (); // 或者 response.json() 取决于你的响应内容类型
45
- })
46
- .then (data => {
47
- // 请求成功,处理响应数据
48
- console .log (data);
49
- this .$refs .seeksRelationGraph .setJsonData (data, (seeksRGGraph ) => {
50
- // 这些写上当图谱初始化完成后需要执行的代码
41
+ // 获取参数的值,例如 'index'
42
+ const index = urlParams .get (' index' );
43
+ fetch (' /api/GraphDemo/GetAllGraphs?index=' + index)
44
+ .then (response => {
45
+ if (! response .ok ) {
46
+ throw new Error (' 网络响应不成功,状态码:' + response .status );
47
+ }
48
+ return response .json (); // 或者 response.json() 取决于你的响应内容类型
49
+ })
50
+ .then (data => {
51
+ // 请求成功,处理响应数据
52
+ console .log (data);
53
+ this .$refs .seeksRelationGraph .setJsonData (data, (seeksRGGraph ) => {
54
+ // 这些写上当图谱初始化完成后需要执行的代码
55
+ });
56
+ })
57
+ .catch (error => {
58
+ // 处理错误
59
+ console .error (' 请求出错:' , error);
51
60
});
52
- })
53
- .catch (error => {
54
- // 处理错误
55
- console .error (' 请求出错:' , error);
56
- });
61
+ }
57
62
}
58
- }
59
- })
63
+ })
64
+ }
60
65
</script >
61
66
62
67
@code
63
68
{
64
-
69
+ [Inject ]
70
+ protected IJSRuntime _jsRuntime { get ; set ; }
71
+
72
+ protected override async Task OnAfterRenderAsync (bool firstRender )
73
+ {
74
+ if (firstRender )
75
+ {
76
+ // 确保所有脚本加载完成后,调用初始化 Vue 的 JavaScript 函数
77
+ await Task .Delay (500 ); // 短暂延时
78
+
79
+ try
80
+ {
81
+ await _jsRuntime .InvokeVoidAsync (" initializeVueApp" );
82
+ }
83
+ catch (Exception ex )
84
+ {
85
+ Console .WriteLine (ex .Message );
86
+ }
87
+ }
88
+ }
65
89
}
0 commit comments