-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue-3.txt
5023 lines (4426 loc) · 132 KB
/
vue-3.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
https://cli.vuejs.org/zh/guide/
1 安装nodejs
yum install nod
2
// use npm
npm i nrm -g
查看可用的npm源
nrm ls
nrm use taobao
// 切换之后可用 nrm ls查看是否已经切换了npm源
npm i yarn -g
3 安装vue工具包
npm uninstall -g vue-cli
npm install -g @vue/cli
4 创建项目(cmd到自己项目想产生的位置)
vue create xxx (xxx为项目名);
5 进入到项目根目录:添加iview依赖
npm install iview --save
6 进入到项目根目录:启动项目
npm run serve
7 打包
npm run build
=======================
// 进入到vue-test项目
cd vue-test
// - 启动服务
yarn serve
// - 打包编译
yarn build
// - 执行lint
yarn lint
// - 执行单元测试
yarn test:unit
module.exports = {
devServer: {
proxy: {
'/hrm/api': {
//target: 'http:https://192.168.1.209:10751/', // Dev环境
// target: 'http:https://192.168.1.238:10751/', // Test环境
// target: 'http:https://192.168.1.215:10751/', // Rls环境
target: 'http:https://192.168.1.218:10751/', // 正式环境
changeOrigin: true,
autoRewrite: true,
cookieDomainRewrite: true,
pathRewrite: {
'^/hrm/api/': '/'
}
}
}
}
}
vi nginx.conf
server {
location / {
root /software/dist;
index index.html index.html;
}
/usr/local/nginx/sbin/nginx -s reload
npm upgrade -g core-js@^3
npm update常用命令使用
一、更新
npm-check检查更新
npm install -g npm-check
npm-check
2.npm-upgrade更新
npm install -g npm-upgrade
npm-upgrade
3.更新全局包:
npm update <name> -g
4.更新生产环境依赖包:
npm update <name> --save
5.更新开发环境依赖包:
npm update <name> --save-dev
安装sinopia
npm install -g sinopia
安装成功之后,修改npm路径为本地,
npm set registry http:https://localhost:4873/
$ npm set ca null
如果使用HTTPS,请添加适当的CA信息,(“null”表示从操作系统获取CA列表)
添加新用户
npm adduser --registry http:// localhost:4873 /
sudo npm cache verify
解决方案 由于 npm 5 使用了新的包管理模式,所以在升级之后,请先清空一下本地缓存:
npm cache clean --force 。
如果上边没办法解决问题,可以尝试下边的指令:
npm cache clear --force && npm install --no-shrinkwrap --update-binary
yarn global add @vue/cli
yarn global add sinopia
yarn global add pm2
npm 与 yarn 命令对比
npm yarn
npm install yarn install
(N/A) yarn install --flat
(N/A) yarn install --har
(N/A) yarn install --no-lockfile
(N/A) yarn install --pure-lockfile
npm install [package] (N/A)
npm install --save [package] yarn add [package]
npm install --save-dev [package] yarn add [package] [--dev/-D]
(N/A) yarn add [package] [--peer/-P]
npm install --save-optional [package] yarn add [package] [--optional/-O]
npm install --save-exact [package] yarn add [package] [--exact/-E]
(N/A) yarn add [package] [--tilde/-T]
npm install --global [package] yarn global add [package]
npm rebuild yarn install --force
npm uninstall [package] (N/A)
npm uninstall --save [package] yarn remove [package]
npm uninstall --save-dev [package] yarn remove [package]
npm uninstall --save-optional [package] yarn remove [package]
npm cache clean yarn cache clean
rm -rf node_modules && npm install yarn upgrade
yarn add iview
yarn add serve
[root@dns demo]# more src/main.js
import Vue from 'vue'
import App from './App.vue'
import iView from 'iview'
import 'iview/dist/styles/iview.css'
Vue.config.productionTip = false
Vue.use(iView)
vue add router
yarn serve
vue ui
yarn build
===================
Set correct publicPath in vue.config.js.
If you are deploying to https://<USERNAME>.github.io/, you can omit publicPath as it defaults to "/".
If you are deploying to https://<USERNAME>.github.io/<REPO>/, (i.e. your repository is at https://github.com/<USERNAME>/<REPO>), set publicPath to "/<REPO>/". For example, if your repo name is "my-project", your vue.config.js should look like this:
module.exports = {
publicPath: process.env.NODE_ENV === 'production'
? '/my-project/'
: '/'
}
nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /app; ### 根据这里定位静态文件
index index.html;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
https://cli.vuejs.org/guide/deployment.html#docker-nginx
node的测试web服务器
/app/sample/node_modules/.bin/serve -s dist
private:npm仓库名称
nrm add private http:https://192.168.152.128:4873
nrm use private
添加用户的ip,可能是用户识别的一部分
npm adduser --registry http:https://localhost:4873/
nrm add local http:https://localhost:4873/
nrm use local
npm login
npm publish
npm unpublish --force
/root/.config/sinopia/config.yaml
config.yaml文件是sinopia的配置文件
storage: ./storage //npm包存放的路径
auth:
htpasswd:
file: ./htpasswd //保存用户的账号密码等信息
max_users: -1 //默认为1000,改为-1,禁止注册
uplinks:
npmjs:
url: http:https://registry.npm.taobao.org/ //默认为npm的官网,由于国情,修改 url 让sinopia使用 淘宝的npm镜像地址
packages: //配置权限管理
'@*/*':
access: $all
publish: $authenticated
'*':
access: $all
publish: $authenticated
proxy: npmjs
logs:
- {type: stdout, format: pretty, level: http}
listen: 0.0.0.0:4873 ////默认没有,只能在本机访问,添加后可以通过外网访问。
yarn global add @vue/cli
vue --version
Vue-cli3如何添加路由(router)
npm install vue-router
创建router.js与mian.js同级
router.js中的内容为
import Vue from 'vue'
import Router from 'vue-router'
//组件模块
import Main from './components/content/main'
import Header from './components/header/header'
import Admin from './components/admin/admin'
Vue.use(Router)
export default new Router({
routes: [
{ path: '/', name: 'home', component: Main },
{ path: '/main', name: 'Main', component: Main },
{ path: '/header', name: 'Header', component: Header},
{ path: '/admin', name: 'Admin', component: Admin}
]
})
在main.js中添加如下内容
import router from './router'
new Vue({
render: h => h(App),
router, //here
}).$mount('#app')
接下里就可以开始使用路由了,在需要使用路由的地方加入以下内容
也可通过事件的方法来使用路由
methods:{
toMain() {
this.$router.push('./main'); //跳转到指定组件
},
//使用路由返回上一级
goBack() {
window.history.length > 1 ? this.$router.go(-1) : this.$router.push("/");
},
}
安装vue-router
yarn add vue-router
在src文件夹下创建router文件夹,router文件夹里面创建index.js文件,index.js内容为:
src/router/index.js
import Vue from 'vue'
import Router from 'vue-router'
import App from '@/views/App.vue'
const requireAll = requireContext => requireContext.keys().map(requireContext)
const routerChildrenContext = require.context('@/views/', true, /router\.js$/)
Vue.use(Router)
let routes = []
let rootRouter = {
path: '/',
component: App,
children: []
}
// 重定向路由
let redirectRoute = {
path: '*',
redirect: '/'
}
const routerChildren = requireAll(routerChildrenContext)
routerChildren.map((route) => {
route.default(rootRouter.children)
})
let mode = 'history'
const relRoutes = routes.concat([rootRouter, redirectRoute])
export default new Router({
mode: mode,
routes: relRoutes
})
在main.js文件中引用上面的index.js文件
因为在src/router/index.js文件中已经引入App.vue 文件,在main.js中就不再引入渲染
src/main.js
import Vue from 'vue'
// import App from './App.vue'
import router from './router/index' // 引入
Vue.config.productionTip = false
new Vue({
// render: h => h(App),
router
}).$mount('#app')
4.引用组件
在src目录下新建views文件夹(存放前端页面组件),已经存在的components我们存放elementUI组件和自定义的公用组件
在views文件夹下创建页面模块文件夹,这里是ceshi文件夹
ceshi文件夹下创建router.js文件和src文件夹
src文件下存放vue组件
src/views/ceshi/router.js
const A = () => import('./src/a.vue')
const B = () => import('./src/b.vue')
export default function (router) {
router.push({
path: '/a',
name: 'a',
component: A
}, {
path: '/b',
name: 'b',
component: B
})
}
渲染路由组件
src/views/App.vue
<template>
<div id="app">
<img alt="Vue logo" src="@/assets/logo.png">
<router-view/>
</div>
</template>
<script>
export default {
name: 'app'
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
将public/index.html文件中的<div id="app"><router-view></router-view></div>改为<div id="app"></div>
启动项目 发现有报错信息如下:
[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.
原因参考这边文章:https://blog.csdn.net/qq_35324453/article/details/80920344
#解决方案:
在项目根目录创建vue.config.js文件添加配置
方案一:
module.exports = {
runtimeCompiler: true
}
方案二:
module.exports = {
configureWebpack: {
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
}
}
}
重启项目,打开 http:https://localhost:8080就可以切换路由展示不同页面啦
封装axios请求
#安装axios
yarn add axios
#引入axios并封装
src文件夹下创建config文件夹,config文件夹下创建axios.config.js和http.js文件
src/config/axios.config.js
import axios from 'axios'
const service = axios.create({
timeout: 20000,
withCredentials: true // 跨站点访问控制请求
})
/**
* 请求配置
* @see https://github.com/mzabriskie/axios
*/
service.interceptors.request.use(function (config) {
return config
}, function (error) {
// Do something with request error
return Promise.reject(error)
})
service.interceptors.response.use(function (response) {
let { data, status, statusText: err_msg } = response
return { data, status, err_msg }
}, function (error) {
// Do something with response error
return Promise.reject(error)
})
export default service
src/config/http.js
import fetch from './axios.config'
const API_HOST = '/api'
// 基本配置
const DEFAULT_CONFIG ={
isApiHost: true
}
const POST_HEADER = {
headers: {
'content-type': 'application/json'
}
}
/**
* get 提交
* @param {String} url 请求的url
* @param {any} params 请求的参数
* @param {Obejct} config 请求配置
* @returns Promise
*/
export function get(url, params = {}, config = {}) {
let opts = {...DEFAULT_CONFIG, ...config}
opts.params = {...params}
return fetch.get(getUrl(url, opts.isApiHost), opts)
}
/**
*
* post 提交
* @param {String} url 请求的url
* @param {any} [params={}] 请求的参数
* @param {any} isApiHost 请求配置
* @returns Promise
*
* @memberOf HttpBase
*/
export function post(url, params = {}, config = {}) {
let opts = {...DEFAULT_CONFIG, ...POST_HEADER, ...config}
return fetch.post(getUrl(url, opts.isApiHost), params, opts)
}
/**
*
* delete 提交
* @param {String} url 请求的url
* @param {any} [params={}] 请求的参数
* @returns Promise
*
* @memberOf HttpBase
*/
export function Delete(url, params = {}, config = {}) {
let opts = {...DEFAULT_CONFIG, ...POST_HEADER, ...config}
return fetch.delete(getUrl(url, opts.isApiHost), params, opts)
}
/**
*
* 上传
* @export
* @param {any} url 请求的url
* @param {any} [params={}] 请求的参数
* @param {any} [config={}] 配置
* @returns Promise
*/
export function upload(url, params = {}, config = {}) {
let opts = {...DEFAULT_CONFIG, ...POST_HEADER, ...config}
let form = new FormData()
Object.keys(params).forEach(key => {
form.append(key, params[key])
})
return fetch.post(getUrl(url, opts.isApiHost), form, opts)
}
/**
*
* 下载
* @export
* @param {any} url 请求
* @param {any} [params={}] 请求参数
* @param {string} [type='post'] 请求类型
* @param {any} [config={}] 配置
*/
export function download(url, params = {}, type = 'post', config = {}) {
let opts = {...DEFAULT_CONFIG, ...POST_HEADER, ...config}
let $form = document.createElement('form')
$form.setAttribute('method', type)
$form.setAttribute('hidden', 'hidden')
$form.setAttribute('action', getUrl(url, opts.isApiHost))
let createInput = (name, value) => {
let input = document.createElement('input')
input.setAttribute('type', 'hidden')
input.setAttribute('name', name)
input.setAttribute('value', value)
$form.appendChild(input)
}
Object.keys(params).forEach(key => {
createInput(key, params[key])
})
let $body = document.body || document.getElementsByTagName('body')[0]
$body.append($form)
$form.submit()
$form.remove()
}
/**
*
* url 处理如果 isApiHost 为true 则添加 API_HOST
* @param {any} url
* @param {any} isApiHost
* @returns
*
*/
function getUrl(url, isApiHost) {
if (!isApiHost) {
return url
}
let arr = [API_HOST]
arr.push(url)
return arr.join('')
}
#调用接口
src文件夹下创建services文件夹,这里用来存放前端调用的接口,services文件夹下创建ceshi.service.js文件
src/services/ceshi.service.js
/info是我们在最初写的接口例子
import { get } from '@/config/http'
export function getInfoData () {
return get('/info')
}
页面内调用接口
src/views/ceshi/src/a.vue
<template>
<div>
<div>aaaaaaaa</div>
<button v-on:click="getInfo()">点击获取数据</button>
{{infoList}}
</div>
</template>
<script>
import { getInfoData } from '@/services/ceshi.service' // 引入接口
export default {
data() {
return {
infoList: []
}
},
methods: {
async getInfo() {
const result = await getInfoData()
this.infoList = result
}
}
}
</script>
配置代理
上面我们前端启动的项目地址是http:https://localhost:8080, node启动的服务地址是http:https://localhost:3000
在项目根目录的vue.config.js文件中配置代理
vue.config.js
module.exports = {
runtimeCompiler: true,
// 配置代理
devServer: {
proxy: {
'/api': {
target: 'http:https://localhost:3000',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
}
}
}
启动项目
前端:
yarn serve
后端:
node core/app.js
http:https://localhost:8080/sockjs-node/info?t=1556418283950 net:: ERR_CONNECTION_REFUSED(亲测有效~!)
如果你的项目没有用到sockjs,vuecli3 运行npm run serve 之后network里面一直调用一个接口:
http:https://localhost:8080/sockjs-node/info?t=1556418283950 net:: ERR_CONNECTION_REFUSED
原因:network里一直调用的这个借口其实是不存在的,所以导致一直报错。
方案:从根源上关闭此调用
1、node_modules/sockjs-client/dist/sockjs.js
2、代码的1605行注释
// self.xhr.send(payload);
#ps:可在代码开发完成后关闭,会同步关闭热加载
在main.js中添加了
import iView from 'iview'
import 'iview/dist/styles/iview.css' // 使用 CSS
Vue.use(iView)
src/App.vue:
<template>
<div id="app">
<LoginForm></LoginForm>
</div>
</template>
<script>
import LoginForm from './components/LoginForm'
export default {
name: 'app',
components: {
'LoginForm': LoginForm
}
}
</script>
<style>
#app {
}
</style>
使用iview 组件
创建 src/components/LoginForm.vue
<template>
<div>
<Form ref="formInline" :model="formInline" :rules="ruleInline" inline>
<FormItem prop="user">
<Input type="text" v-model="formInline.user" placeholder="Username">
<Icon type="ios-person-outline" slot="prepend"></Icon>
</Input>
</FormItem>
<FormItem prop="password">
<Input type="password" v-model="formInline.password" placeholder="Password">
<Icon type="ios-locked-outline" slot="prepend"></Icon>
</Input>
</FormItem>
<FormItem>
<Button type="primary" @click="handleSubmit('formInline')">登录</Button>
</FormItem>
</Form>
</div>
</template>
<script>
export default {
data () {
return {
formInline: {
user: '',
password: ''
},
ruleInline: {
user: [
{ required: true, message: '请填写用户名', trigger: 'blur' }
],
password: [
{ required: true, message: '请填写密码', trigger: 'blur' },
{ type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
]
}
}
},
methods: {
handleSubmit (name) {
this.$refs[name].validate((valid) => {
if (valid) {
this.$Message.success('提交成功!')
} else {
this.$Message.error('表单验证失败!')
}
})
}
}
}
</script>
response.data不是数组,所以没有forEach这个方法。response.data.results才是你需要的数组吧
,
{
title:"操作",
key:"actor",
align:'center',
render: (h, params) => {
if(this.giftCardsList[params.index].status === '进行中'){
return h('div', [
h('Button', {
props: {
type: 'primary',
size: 'small'
},
style: {
marginRight: '5px'
},
on: {
click: () => {
this.$router.push({ path: '../marketing_manage/add_gift_card?gcid=' + this.giftCardsList[params.index].gcid});
}
}
}, '编辑'),
h('Button', {
props: {
type: 'error',
size: 'small'
},
on: {
click: () => {
this.popupIsShow = true;
this.gcid = this.giftCardsList[params.index].gcid;
}
}
}, '使失效')
]);
}else{
return h('div', [
h('Button', {
props: {
type: 'primary',
size: 'small'
},
on: {
click: () => {
this.$router.push({ path: '../marketing_manage/gift_card_warehouse?gcid=' + this.giftCardsList[params.index].gcid});
}
}
}, '码库')
]);
}
}
}
ceshi.service.js
import { get } from '@/config/http'
export function getUserData() {
return get('/users')
}
import { getUserData } from "@/services/ceshi.service"; // 引入接口
export default {
data() {
},
created(){
this.data = [
{
name: "李小红",
age: 30,
birthday: "563472000000",
address: "上海市浦东新区世纪大道"
},
{
name: "周小伟",
age: 26,
birthday: "687024000000",
address: "深圳市南山区深南大道"
}
];
console.log("wine")
},
methods: {
async getInfo() {
const result = await getUserData();
this.data = result.data;
}
<i-table height="660" border :content="self" :columns="columns" :data="warehouseList" ref="table" @on-selection-change="gccidArr"></i-table>
<i-button style="margin-top:10px" type="primary" size="large" @click="exportData()"><Icon type="ios-download-outline"></Icon> 导出数据 </i-button>
columns:[
{
type: 'selection',
width: 50,
align: 'center',
},
methods: {
gccidArr(selection){
this.selection = selection;
},
exportData: function(){
let self = this;
this.$refs.table.exportCsv({
filename: '码库',
original: false,
columns: self.columns,
data: self.selection
});
},
<i-table height="660" border :content="self" :columns="columns" :data="warehouseList" ref="table" @on-selection-change="gccidArr"></i-table>
意思就是在data对象(就是后台返回的数据,也即应用table里的数据,也就是上文在HTML代码里的:data="warehouseList"里 的warehouseList)里面添加一个属性_disabled,且它的值为true即可,看JS代码:
handleDeadline: function(warehouseList){
warehouseList.forEach(element => {
if(element.status == '0'){
element['_disabled'] = true;
}
});
return warehouseList;
},
{
title: 'Action',
key: 'action',
width: 150,
align: 'center',
render: (h, params) => {
return h('div', [
h('Button', {
props: {
type: 'primary',
size: 'small'
},
style: {
marginRight: '5px'
},
on: {
click: () => {
this.show(params.index)
}
}
}, 'View')
]);
}
由文档得知,table组件提供一个api:render函数,可以自定义渲染当前列,包括渲染自定义组件,它基于 Vue 的 Render 函数。
参数解读:
h: vue Render函数的别名(全名 createElement)即 Render函数
params: table 该行内容的对象
props:设置创建的标签对象的属性
style:设置创建的标签对象的样式
on:为创建的标签绑定事件
所以代码中的render函数,即创建的一个div中包裹一个button按钮,同时给button设置了相关属性和绑定事件
<template>
<div class="meeting">
<Table border :columns="columns" :data="data" :height="tableHeight"></Table>
</div>
</template>
<script>
export default {
name: "meeting",
data() {
let t = this
return {
tableHeight:'550',
columns: [
{
title: '责任人',
key: 'associated',
width: 100,
align: 'center',
},
{
title: '预计工时',
key: 'attendee',
width: 100,
align: 'center',
render:(h,params) => {
return h('Input',{
props: {
value:'',
size:'small',
},