Skip to content

Commit cb4bbf1

Browse files
committed
npm
0 parents  commit cb4bbf1

24 files changed

+13846
-0
lines changed

.editorconfig

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[*.{js,jsx,ts,tsx,vue}]
2+
indent_style = space
3+
indent_size = 2
4+
trim_trailing_whitespace = true
5+
insert_final_newline = true

.gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
5+
6+
# local env files
7+
.env.local
8+
.env.*.local
9+
10+
# Log files
11+
npm-debug.log*
12+
yarn-debug.log*
13+
yarn-error.log*
14+
pnpm-debug.log*
15+
16+
# Editor directories and files
17+
.idea
18+
.vscode
19+
*.suo
20+
*.ntvs*
21+
*.njsproj
22+
*.sln
23+
*.sw?

.npmignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# 忽略目录
2+
examples/
3+
packages/
4+
public/
5+
6+
# 忽略指定文件
7+
vue.config.js
8+
babel.config.js
9+
*.map

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# vue-uploader-files
2+
3+
## 安装
4+
```
5+
npm install vue-uploader-files
6+
```
7+
8+
### main.js引入
9+
```
10+
import upfile from 'vue-uploader-files';
11+
import 'vue-uploader-files/lib/vue-uploader-files.css';
12+
Vue.use(upfile);
13+
```
14+
15+
### 使用
16+
```
17+
<up-file @upfile="upfile"></up-file>
18+
```
19+
20+
### Attribute
21+
22+
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
23+
| ---- | ---- | ---- | ---- | ---- |
24+
| styleSwitch | 是否使用样式(不包含背景色和文字颜色) | Boolean | true,false | true |
25+
| fileName | 上传的文件字段名 | String || file |
26+
| text | 文本内容 | String || 选择文件 |
27+
| backgroundColor | 背景颜色 | String || #0096fa |
28+
| color | 文本颜色 | String || #f5f5f5 |
29+
30+
### Methods
31+
32+
| 方法名 | 说明 | 参数 |
33+
| ---- | ---- | ---- |
34+
| upfile | 返回数据 | (formdata:返回的FormData数据) |

babel.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
'@vue/cli-plugin-babel/preset'
4+
]
5+
}

examples/App.vue

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<div id="app">
3+
<up-file @upfile="upfile"></up-file>
4+
</div>
5+
</template>
6+
7+
<script>
8+
export default {
9+
name: 'App',
10+
components: { },
11+
methods: {
12+
upfile (formdata) {
13+
console.log(formdata.get('file'))
14+
}
15+
}
16+
}
17+
</script>
18+
19+
<style lang="less"></style>

examples/components/index.vue

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<template>
2+
<div
3+
:class="{ 'up-file': styleSwitch }"
4+
:style="{ backgroundColor: backgroundColor, color: color }"
5+
@click="proposal"
6+
>
7+
<span>{{text}}</span>
8+
<input type="file" :name="fileName" id="file" ref="file" @change="upfile" />
9+
</div>
10+
</template>
11+
12+
<script>
13+
export default {
14+
props: {
15+
fileName: {
16+
type: String,
17+
default: 'file'
18+
},
19+
text: {
20+
type: String,
21+
default: '选择文件'
22+
},
23+
backgroundColor: {
24+
type: String,
25+
default: '#0096fa'
26+
},
27+
color: {
28+
type: String,
29+
default: '#f5f5f5'
30+
},
31+
styleSwitch: {
32+
type: Boolean,
33+
default: true
34+
}
35+
},
36+
methods: {
37+
proposal () {
38+
this.$refs.file.click()
39+
},
40+
upfile () {
41+
const formdata = new FormData()
42+
formdata.append(this.$props.fileName, this.$refs.file.files[0])
43+
this.$emit('upfile', formdata)
44+
}
45+
}
46+
}
47+
</script>
48+
49+
<style lang="less" scoped>
50+
.up-file {
51+
width: 232px;
52+
height: 46px;
53+
display: flex;
54+
align-items: center;
55+
justify-content: center;
56+
padding: 14px 80px;
57+
line-height: 1;
58+
font-size: 18px;
59+
font-weight: 700;
60+
border-radius: 5px;
61+
box-sizing: border-box;
62+
cursor: pointer;
63+
#file {
64+
display: none;
65+
}
66+
}
67+
</style>

examples/main.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Vue from 'vue'
2+
import App from './App.vue'
3+
4+
import upfile from '../packages/index'
5+
6+
Vue.use(upfile)
7+
8+
Vue.config.productionTip = false
9+
10+
new Vue({
11+
render: h => h(App)
12+
}).$mount('#app')

lib/demo.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<meta charset="utf-8">
2+
<title>vue-uploader-files demo</title>
3+
<script src="./vue-uploader-files.umd.js"></script>
4+
5+
<link rel="stylesheet" href="./vue-uploader-files.css">
6+
7+
8+
<script>
9+
console.log(vue-uploader-files)
10+
</script>

0 commit comments

Comments
 (0)