Skip to content

Commit fbaf82e

Browse files
committed
- 增加 options 参数的双向绑定处理
1 parent 76bda61 commit fbaf82e

File tree

7 files changed

+148
-28
lines changed

7 files changed

+148
-28
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@
5656
- `added`, 对应`plupload` 事件 `FilesAdded`。
5757
- `progress`, 对应`plupload` 事件 `UploadProgress`。
5858
- `uploaded`, 对应`plupload` 事件 `FileUploaded`。
59-
- `error`, 对应`plupload` 事件 `Error`。
59+
- `error`, 对应`plupload` 事件 `Error`。
60+
61+
## 属性
62+
63+
组件暴露 一个属性 `uploader` 指向所创建的 `plupload` 实例。

dist/vue-plupload.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-plupload.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/bundle.js

Lines changed: 84 additions & 12 deletions
Large diffs are not rendered by default.

docs/index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
<h1>Plupload wrapper for Vue 1.x <small>Example:</small></h1>
1818
</div>
1919
<div class="jumbotron">
20-
<vue-plupload @added="handleAdded" @progress="handleProgress" @error="handleError" @uploaded="handleUploaded" :options="uploadOpt"></vue-plupload>
20+
<vue-plupload @added="handleAdded" @progress="handleProgress" @error="handleError" @uploaded="handleUploaded" :options.sync="uploadOpt"></vue-plupload>
21+
<div class="btn-group">
22+
<button @click="setOption(1)" class="btn btn-default" type="button">With Params 1</button>
23+
<button @click="setOption(2)" class="btn btn-default" type="button">With Params 2</button>
24+
<button @click="setOption(3)" class="btn btn-default" type="button">With Params 3</button>
25+
</div>
2126
</div>
2227
<div class="form-group">
2328
<label>Log:</label>
@@ -45,6 +50,9 @@ <h1>Plupload wrapper for Vue 1.x <small>Example:</small></h1>
4550
},
4651

4752
methods: {
53+
setOption : function(val) {
54+
Vue.set(this.uploadOpt, "multipart_params", {test: val});
55+
},
4856
handleAdded: function (uploader, files) {
4957
files.forEach(function (file) {
5058
vm.log += "begin upload file:" + file.name + "\n";

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-plupload",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "plupload wrapper for vue 1.x",
55
"main": "index.js",
66
"scripts": {

src/vue-plupload.vue

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,41 @@ module.exports = Vue.extend({
5050
}
5151
}
5252
},
53+
54+
data : function() {
55+
return {
56+
uploader: null
57+
}
58+
},
5359
5460
detached: function() {
5561
5662
},
57-
58-
attached: function () {
59-
var self = this;
60-
61-
Vue.nextTick(function () {
62-
63-
var opt = _.merge(uploaderDefaultOption, self.options, {
63+
64+
watch : {
65+
"options" : {
66+
handler: function(val, oldVal) {
67+
var self = this;
68+
69+
if (!self.uploader) {
70+
self.renderPlupload();
71+
} else {
72+
var opt = self.mergeOptions(val);
73+
self.uploader.setOption(opt);
74+
}
75+
76+
console.log("options change!");
77+
console.log(val)
78+
},
79+
deep: true
80+
}
81+
},
82+
83+
methods: {
84+
mergeOptions: function(val) {
85+
var self = this;
86+
87+
return _.merge(uploaderDefaultOption, val, {
6488
6589
browse_button: self.$els.btn,
6690
@@ -85,12 +109,24 @@ module.exports = Vue.extend({
85109
self.$emit("error", up, err)
86110
}
87111
}
88-
})
112+
});
113+
},
114+
renderPlupload: function() {
115+
var self = this;
116+
117+
Vue.nextTick(function () {
118+
119+
var opt = self.mergeOptions(self.options);
89120
90-
var uploader = new plupload.Uploader(opt);
121+
self.uploader = new plupload.Uploader(opt);
91122
92-
uploader.init();
93-
});
123+
self.uploader.init();
124+
});
125+
}
126+
},
127+
128+
attached: function () {
129+
this.renderPlupload();
94130
}
95131
});
96132

0 commit comments

Comments
 (0)