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

feat(v3): __wxUsingComponents

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