-
Notifications
You must be signed in to change notification settings - Fork 0
/
v-ajax-form.js
210 lines (179 loc) · 6.42 KB
/
v-ajax-form.js
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
(function () {
'use strict';
//
//
//
//
//
var VAjaxForm_vue_rollupPluginVue_script = {
props: {
action: String,
method: String,
uriEncode: Boolean
}, methods: {
request: function (params) {
var vm = this;
vm.$emit('start', params);
var ax_op2 = {};
var _method = vm.method.toLowerCase();
switch (vm.method) {
case 'get':
ax_op2 = {params: params};
break;
case 'post':
ax_op2 = params;
break;
}
axios[_method](vm.action,
ax_op2
).then(function (response) {
vm.$emit('receive', response);
}).catch(function (response) {
vm.$emit('fail', response);
}).finally(function () {
vm.$emit('done', params);
});
}, submit: function () {
var params = {};
var vm = this;
vm.$el.querySelectorAll('input,select,textarea').forEach(function(el){
if ((typeof el.attributes['disabled'] === 'undefined')
&& (typeof el.attributes['name'] != 'undefined')
) {
if ((el.type === 'radio' || el.type === 'checkbox') && !el.checked) { return; }
var val = el.value;
var name = el.attributes['name'].value;
if(vm.uriEncode) {
val = encodeURIComponent(val);
name = encodeURIComponent(name);
}
if (typeof params[name] === 'undefined') {
params[name] = val;
} else if (params[name] instanceof Array) {
params[name].push(val);
} else {
params[name] = [params[name], val];
}
}
});
vm.request(params);
}
}
};
function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier
/* server only */
, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
if (typeof shadowMode !== 'boolean') {
createInjectorSSR = createInjector;
createInjector = shadowMode;
shadowMode = false;
} // Vue.extend constructor export interop.
var options = typeof script === 'function' ? script.options : script; // render functions
if (template && template.render) {
options.render = template.render;
options.staticRenderFns = template.staticRenderFns;
options._compiled = true; // functional template
if (isFunctionalTemplate) {
options.functional = true;
}
} // scopedId
if (scopeId) {
options._scopeId = scopeId;
}
var hook;
if (moduleIdentifier) {
// server build
hook = function hook(context) {
// 2.3 injection
context = context || // cached call
this.$vnode && this.$vnode.ssrContext || // stateful
this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext; // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__;
} // inject component styles
if (style) {
style.call(this, createInjectorSSR(context));
} // register component module identifier for async chunk inference
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier);
}
}; // used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook;
} else if (style) {
hook = shadowMode ? function () {
style.call(this, createInjectorShadow(this.$root.$options.shadowRoot));
} : function (context) {
style.call(this, createInjector(context));
};
}
if (hook) {
if (options.functional) {
// register for functional component in vue file
var originalRender = options.render;
options.render = function renderWithStyleInjection(h, context) {
hook.call(context);
return originalRender(h, context);
};
} else {
// inject component registration as beforeCreate hook
var existing = options.beforeCreate;
options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
}
}
return script;
}
var normalizeComponent_1 = normalizeComponent;
/* script */
var __vue_script__ = VAjaxForm_vue_rollupPluginVue_script;
/* template */
var __vue_render__ = function() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c(
"form",
_vm._b(
{
attrs: { action: this.action, method: this.method },
on: {
submit: function($event) {
$event.preventDefault();
return _vm.submit($event)
}
}
},
"form",
_vm.$attrs,
false
),
[_vm._t("default")],
2
)
};
var __vue_staticRenderFns__ = [];
__vue_render__._withStripped = true;
/* style */
var __vue_inject_styles__ = undefined;
/* scoped */
var __vue_scope_id__ = undefined;
/* module identifier */
var __vue_module_identifier__ = undefined;
/* functional template */
var __vue_is_functional_template__ = false;
/* style inject */
/* style inject SSR */
var VAjaxForm = normalizeComponent_1(
{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
__vue_inject_styles__,
__vue_script__,
__vue_scope_id__,
__vue_is_functional_template__,
__vue_module_identifier__,
undefined,
undefined
);
Vue.component('VAjaxForm', VAjaxForm);
}());
//# sourceMappingURL=v-ajax-form.js.map