提交 9123bd64 编写于 作者: fxy060608's avatar fxy060608

feat(v3): __wxUsingComponents

上级 c248919d
...@@ -4754,7 +4754,7 @@ var serviceContext = (function () { ...@@ -4754,7 +4754,7 @@ var serviceContext = (function () {
}); });
}, },
indexOf (page) { indexOf (page) {
const itemLength = config.list.length; const itemLength = config && config.list && config.list.length;
if (itemLength) { if (itemLength) {
for (let i = 0; i < itemLength; i++) { for (let i = 0; i < itemLength; i++) {
if ( if (
...@@ -6048,7 +6048,7 @@ var serviceContext = (function () { ...@@ -6048,7 +6048,7 @@ var serviceContext = (function () {
hasContentType = true; hasContentType = true;
headers['Content-Type'] = header[name]; headers['Content-Type'] = header[name];
// TODO 需要重构 // TODO 需要重构
if(method === 'POST' && header[name].indexOf('application/x-www-form-urlencoded') === 0) { if (method === 'POST' && header[name].indexOf('application/x-www-form-urlencoded') === 0) {
let bodyArray = []; let bodyArray = [];
for (let key in data) { for (let key in data) {
if (data.hasOwnProperty(key)) { if (data.hasOwnProperty(key)) {
...@@ -12288,7 +12288,18 @@ var serviceContext = (function () { ...@@ -12288,7 +12288,18 @@ var serviceContext = (function () {
lifecycleMixin(Vue); lifecycleMixin(Vue);
Vue.mixin({ Vue.mixin({
beforeCreate () { beforeCreate () {
// TODO 临时解决方案,service 层也注入 wxs (适用于工具类)
const options = this.$options;
const wxs = options.wxs;
if (wxs) {
Object.keys(wxs).forEach(module => {
this[module] = wxs[module];
});
}
if (this.mpType === 'page') { if (this.mpType === 'page') {
this.$scope = this.$options.pageInstance; this.$scope = this.$options.pageInstance;
this.$scope.$vm = this; this.$scope.$vm = this;
......
...@@ -7,7 +7,7 @@ const { ...@@ -7,7 +7,7 @@ const {
function transformScript(content, route, usingComponentsCode) { function transformScript(content, route, usingComponentsCode) {
return `global['__wxRoute'].push('${route}') return `global['__wxRoute'].push('${route}')
global['__wxUsingComponents'] = ${usingComponentsCode} global['__wxUsingComponents'].push(${usingComponentsCode})
${content} ${content}
export default global['__wxComponents']['${route}']` export default global['__wxComponents']['${route}']`
} }
......
...@@ -71,13 +71,14 @@ const v3 = { ...@@ -71,13 +71,14 @@ const v3 = {
'../../packages/webpack-uni-app-loader/view/script') '../../packages/webpack-uni-app-loader/view/script')
}] }]
}) })
rules.push({ }
resourceQuery: [/lang=wxs/, /blockType=wxs/], // TODO 临时方案,将 wxs 也编译至 service
use: [{ rules.push({
loader: path.resolve(__dirname, '../../packages/webpack-uni-filter-loader') resourceQuery: [/lang=wxs/, /blockType=wxs/],
}] use: [{
}) loader: path.resolve(__dirname, '../../packages/webpack-uni-filter-loader')
} }]
})
const entry = {} const entry = {}
if (isAppService) { if (isAppService) {
......
...@@ -7,13 +7,12 @@ import polyfill from './polyfill' ...@@ -7,13 +7,12 @@ import polyfill from './polyfill'
export * from './wxs' export * from './wxs'
global['__wxRoute'] = [] global['__wxRoute'] = []
global['__wxComponents'] = Object.create(null)
global['__wxUsingComponents'] = []
export function Component (options) { export function Component (options) {
const componentOptions = parseComponent(options) const componentOptions = parseComponent(options)
componentOptions.mixins.unshift(polyfill) componentOptions.mixins.unshift(polyfill)
if (!global['__wxComponents']) {
global['__wxComponents'] = Object.create(null)
}
global['__wxComponents'][global['__wxRoute'].pop()] = componentOptions global['__wxComponents'][global['__wxRoute'].pop()] = componentOptions
} }
......
...@@ -6,6 +6,10 @@ import { ...@@ -6,6 +6,10 @@ import {
parseProperties parseProperties
} from './properties-parser' } from './properties-parser'
import {
parseComponents
} from './components-parser'
import { import {
parseOptions parseOptions
} from './options-parser' } from './options-parser'
...@@ -68,6 +72,8 @@ export function parseComponent (mpComponentOptions) { ...@@ -68,6 +72,8 @@ export function parseComponent (mpComponentOptions) {
} }
} }
parseComponents(vueComponentOptions)
parseData(data, vueComponentOptions) parseData(data, vueComponentOptions)
parseOptions(options, vueComponentOptions) parseOptions(options, vueComponentOptions)
parseMethods(methods, vueComponentOptions) parseMethods(methods, vueComponentOptions)
......
export function parseComponents (vueComponentOptions) {
vueComponentOptions.components = global['__wxUsingComponents'].pop()
}
...@@ -49,7 +49,17 @@ export function initLifecycle (Vue) { ...@@ -49,7 +49,17 @@ export function initLifecycle (Vue) {
lifecycleMixin(Vue) lifecycleMixin(Vue)
Vue.mixin({ Vue.mixin({
beforeCreate () { beforeCreate () {
// TODO 临时解决方案,service 层也注入 wxs (适用于工具类)
const options = this.$options
const wxs = options.wxs
if (wxs) {
Object.keys(wxs).forEach(module => {
this[module] = wxs[module]
})
}
if (this.mpType === 'page') { if (this.mpType === 'page') {
this.$scope = this.$options.pageInstance this.$scope = this.$options.pageInstance
this.$scope.$vm = this this.$scope.$vm = this
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册