├── .gitignore ├── README.md ├── day-2 ├── .browserslistrc ├── babel.config.js ├── tests │ └── unit │ │ ├── .eslintrc.js │ │ └── example.spec.js ├── postcss.config.js ├── public │ ├── favicon.ico │ └── index.html ├── .editorconfig ├── src │ ├── main.js │ ├── directives │ │ └── clickOutside.js │ ├── App.vue │ └── components │ │ └── CascaderItem.vue ├── .gitignore ├── dist │ ├── Cascader.css │ └── demo.html ├── .eslintrc.js ├── README.md ├── jest.config.js └── package.json ├── day-4 ├── .browserslistrc ├── babel.config.js ├── postcss.config.js ├── public │ ├── favicon.ico │ └── index.html ├── src │ ├── assets │ │ └── logo.png │ ├── types │ │ └── todo.ts │ ├── shims-vue.d.ts │ ├── views │ │ ├── About.vue │ │ └── Home.vue │ ├── main.ts │ ├── shims-tsx.d.ts │ ├── store.ts │ ├── App.vue │ ├── router.ts │ └── components │ │ └── TodoItem.tsx ├── .gitignore ├── tslint.json ├── README.md ├── tsconfig.json └── package.json ├── day-1 ├── vue-jwt │ ├── .browserslistrc │ ├── babel.config.js │ ├── postcss.config.js │ ├── public │ │ ├── favicon.ico │ │ └── index.html │ ├── src │ │ ├── assets │ │ │ └── logo.png │ │ ├── views │ │ │ ├── Profile.vue │ │ │ ├── Home.vue │ │ │ └── Login.vue │ │ ├── api │ │ │ └── index.js │ │ ├── router.js │ │ ├── App.vue │ │ ├── store.js │ │ ├── lib │ │ │ └── ajaxRequest.js │ │ ├── main.js │ │ └── components │ │ │ └── HelloWorld.vue │ ├── .editorconfig │ ├── .gitignore │ ├── README.md │ ├── .eslintrc.js │ ├── package.json │ └── server.js ├── .DS_Store └── vue-component │ ├── package.json │ ├── history1 │ ├── components │ │ ├── Grandson2.vue │ │ ├── Son2.vue │ │ ├── Son1.vue │ │ ├── Grandson1.vue │ │ └── Parent.vue │ └── App.vue │ ├── history2 │ ├── components │ │ ├── ListItem.js │ │ ├── List1.vue │ │ ├── List.vue │ │ ├── LevelFunctional.js │ │ └── Level.vue │ └── App.vue │ ├── main.js │ └── App.vue ├── day-3 ├── vue-auth 2 │ ├── .browserslistrc │ ├── src │ │ ├── views │ │ │ ├── Home.vue │ │ │ ├── Lottery.vue │ │ │ ├── Product.vue │ │ │ ├── Cart.vue │ │ │ └── CartList.vue │ │ ├── assets │ │ │ └── logo.png │ │ ├── components │ │ │ ├── Menu.vue │ │ │ └── MenuItem.vue │ │ ├── App.vue │ │ ├── main.js │ │ ├── router.js │ │ └── store.js │ ├── babel.config.js │ ├── postcss.config.js │ ├── public │ │ ├── favicon.ico │ │ └── index.html │ ├── .gitignore │ ├── README.md │ ├── package.json │ └── server.js ├── vue-router-vux │ ├── .browserslistrc │ ├── src │ │ ├── views │ │ │ ├── About.vue │ │ │ └── Home.vue │ │ ├── assets │ │ │ └── logo.png │ │ ├── App.vue │ │ ├── main.js │ │ ├── store.js │ │ ├── router.js │ │ ├── vuex.js │ │ └── vue-router.js │ ├── babel.config.js │ ├── postcss.config.js │ ├── public │ │ ├── favicon.ico │ │ └── index.html │ ├── .gitignore │ ├── README.md │ ├── package.json │ └── server.js ├── src │ ├── platforms │ │ ├── weex │ │ │ ├── runtime │ │ │ │ ├── directives │ │ │ │ │ └── index.js │ │ │ │ ├── text-node.js │ │ │ │ ├── components │ │ │ │ │ ├── index.js │ │ │ │ │ ├── transition.js │ │ │ │ │ └── richtext.js │ │ │ │ ├── modules │ │ │ │ │ ├── index.js │ │ │ │ │ ├── attrs.js │ │ │ │ │ ├── events.js │ │ │ │ │ ├── class.js │ │ │ │ │ └── style.js │ │ │ │ ├── patch.js │ │ │ │ ├── index.js │ │ │ │ └── recycle-list │ │ │ │ │ └── render-component-template.js │ │ │ ├── compiler │ │ │ │ ├── directives │ │ │ │ │ ├── index.js │ │ │ │ │ └── model.js │ │ │ │ ├── modules │ │ │ │ │ ├── index.js │ │ │ │ │ ├── recycle-list │ │ │ │ │ │ ├── component-root.js │ │ │ │ │ │ ├── v-once.js │ │ │ │ │ │ ├── component.js │ │ │ │ │ │ ├── text.js │ │ │ │ │ │ ├── v-bind.js │ │ │ │ │ │ ├── v-on.js │ │ │ │ │ │ ├── v-for.js │ │ │ │ │ │ ├── recycle-list.js │ │ │ │ │ │ ├── index.js │ │ │ │ │ │ └── v-if.js │ │ │ │ │ ├── append.js │ │ │ │ │ ├── props.js │ │ │ │ │ └── class.js │ │ │ │ └── index.js │ │ │ ├── entry-compiler.js │ │ │ ├── entry-runtime-factory.js │ │ │ └── util │ │ │ │ ├── index.js │ │ │ │ ├── element.js │ │ │ │ └── parser.js │ │ └── web │ │ │ ├── entry-runtime.js │ │ │ ├── server │ │ │ ├── directives │ │ │ │ ├── index.js │ │ │ │ ├── show.js │ │ │ │ └── model.js │ │ │ ├── modules │ │ │ │ ├── index.js │ │ │ │ ├── class.js │ │ │ │ ├── style.js │ │ │ │ ├── dom-props.js │ │ │ │ └── attrs.js │ │ │ └── compiler.js │ │ │ ├── runtime │ │ │ ├── directives │ │ │ │ ├── index.js │ │ │ │ └── show.js │ │ │ ├── components │ │ │ │ └── index.js │ │ │ ├── modules │ │ │ │ ├── index.js │ │ │ │ └── class.js │ │ │ ├── patch.js │ │ │ ├── class-util.js │ │ │ ├── node-ops.js │ │ │ └── index.js │ │ │ ├── compiler │ │ │ ├── directives │ │ │ │ ├── index.js │ │ │ │ ├── html.js │ │ │ │ └── text.js │ │ │ ├── modules │ │ │ │ ├── index.js │ │ │ │ ├── class.js │ │ │ │ └── style.js │ │ │ ├── index.js │ │ │ ├── options.js │ │ │ └── util.js │ │ │ ├── entry-compiler.js │ │ │ ├── entry-server-basic-renderer.js │ │ │ ├── util │ │ │ ├── index.js │ │ │ ├── compat.js │ │ │ ├── attrs.js │ │ │ ├── style.js │ │ │ └── class.js │ │ │ └── entry-server-renderer.js │ ├── core │ │ ├── components │ │ │ └── index.js │ │ ├── vdom │ │ │ ├── modules │ │ │ │ ├── index.js │ │ │ │ └── ref.js │ │ │ └── helpers │ │ │ │ ├── is-async-placeholder.js │ │ │ │ ├── index.js │ │ │ │ ├── get-first-component-child.js │ │ │ │ ├── merge-hook.js │ │ │ │ └── extract-props.js │ │ ├── util │ │ │ ├── index.js │ │ │ ├── perf.js │ │ │ └── lang.js │ │ ├── instance │ │ │ ├── render-helpers │ │ │ │ ├── resolve-filter.js │ │ │ │ ├── bind-object-listeners.js │ │ │ │ ├── resolve-scoped-slots.js │ │ │ │ ├── render-slot.js │ │ │ │ ├── check-keycodes.js │ │ │ │ ├── index.js │ │ │ │ ├── bind-dynamic-keys.js │ │ │ │ ├── render-list.js │ │ │ │ ├── resolve-slots.js │ │ │ │ ├── render-static.js │ │ │ │ └── bind-object-props.js │ │ │ ├── index.js │ │ │ └── inject.js │ │ ├── global-api │ │ │ ├── mixin.js │ │ │ ├── use.js │ │ │ ├── assets.js │ │ │ └── index.js │ │ ├── index.js │ │ └── observer │ │ │ ├── traverse.js │ │ │ ├── array.js │ │ │ └── dep.js │ ├── compiler │ │ ├── directives │ │ │ ├── index.js │ │ │ ├── bind.js │ │ │ └── on.js │ │ ├── parser │ │ │ ├── entity-decoder.js │ │ │ └── text-parser.js │ │ ├── index.js │ │ ├── codeframe.js │ │ └── create-compiler.js │ ├── shared │ │ └── constants.js │ └── server │ │ ├── util.js │ │ ├── optimizing-compiler │ │ └── index.js │ │ ├── create-basic-renderer.js │ │ ├── webpack-plugin │ │ ├── util.js │ │ ├── server.js │ │ └── client.js │ │ ├── template-renderer │ │ ├── parse-template.js │ │ ├── create-async-file-mapper.js │ │ └── template-stream.js │ │ ├── bundle-renderer │ │ └── source-map-support.js │ │ └── write.js ├── .DS_Store └── analyze │ ├── .DS_Store │ └── 看别人的包 package.json中看.md ├── .DS_Store ├── package.json ├── yarn-error.log └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## vue顶尖高手训练营 2 | -------------------------------------------------------------------------------- /day-2/.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | -------------------------------------------------------------------------------- /day-4/.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | -------------------------------------------------------------------------------- /day-1/vue-jwt/.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhufengpeixun/vue-train/HEAD/.DS_Store -------------------------------------------------------------------------------- /day-3/src/platforms/weex/runtime/directives/index.js: -------------------------------------------------------------------------------- 1 | export default { 2 | } 3 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/src/views/Home.vue: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/src/views/Lottery.vue: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /day-1/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhufengpeixun/vue-train/HEAD/day-1/.DS_Store -------------------------------------------------------------------------------- /day-3/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhufengpeixun/vue-train/HEAD/day-3/.DS_Store -------------------------------------------------------------------------------- /day-3/vue-auth 2/src/views/Product.vue: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /day-2/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app', 4 | ], 5 | }; 6 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/src/views/About.vue: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/src/views/Home.vue: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /day-4/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /day-1/vue-component/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "iview": "^3.4.2" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /day-2/tests/unit/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | jest: true, 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /day-4/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | autoprefixer: {} 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /day-1/vue-jwt/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app', 4 | ], 5 | }; 6 | -------------------------------------------------------------------------------- /day-2/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | autoprefixer: {}, 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /day-2/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhufengpeixun/vue-train/HEAD/day-2/public/favicon.ico -------------------------------------------------------------------------------- /day-3/analyze/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhufengpeixun/vue-train/HEAD/day-3/analyze/.DS_Store -------------------------------------------------------------------------------- /day-3/vue-auth 2/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /day-4/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhufengpeixun/vue-train/HEAD/day-4/public/favicon.ico -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "uglifyjs-webpack-plugin": "1.0.0-beta.1" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /day-1/vue-jwt/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | autoprefixer: {}, 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | autoprefixer: {} 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /day-4/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhufengpeixun/vue-train/HEAD/day-4/src/assets/logo.png -------------------------------------------------------------------------------- /day-4/src/types/todo.ts: -------------------------------------------------------------------------------- 1 | export interface ITodo { 2 | text: string; 3 | complete: boolean; 4 | } 5 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | autoprefixer: {} 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /day-4/src/shims-vue.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.vue' { 2 | import Vue from 'vue'; 3 | export default Vue; 4 | } 5 | -------------------------------------------------------------------------------- /day-1/vue-jwt/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhufengpeixun/vue-train/HEAD/day-1/vue-jwt/public/favicon.ico -------------------------------------------------------------------------------- /day-3/src/core/components/index.js: -------------------------------------------------------------------------------- 1 | import KeepAlive from './keep-alive' 2 | 3 | export default { 4 | KeepAlive 5 | } 6 | -------------------------------------------------------------------------------- /day-1/vue-jwt/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhufengpeixun/vue-train/HEAD/day-1/vue-jwt/src/assets/logo.png -------------------------------------------------------------------------------- /day-3/src/platforms/web/entry-runtime.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import Vue from './runtime/index' 4 | 5 | export default Vue 6 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/compiler/directives/index.js: -------------------------------------------------------------------------------- 1 | import model from './model' 2 | 3 | export default { 4 | model 5 | } 6 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhufengpeixun/vue-train/HEAD/day-3/vue-auth 2/public/favicon.ico -------------------------------------------------------------------------------- /day-3/vue-auth 2/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhufengpeixun/vue-train/HEAD/day-3/vue-auth 2/src/assets/logo.png -------------------------------------------------------------------------------- /day-3/vue-auth 2/src/views/Cart.vue: -------------------------------------------------------------------------------- 1 | 7 | -------------------------------------------------------------------------------- /day-1/vue-jwt/src/views/Profile.vue: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhufengpeixun/vue-train/HEAD/day-3/vue-router-vux/public/favicon.ico -------------------------------------------------------------------------------- /day-4/src/views/About.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/src/views/CartList.vue: -------------------------------------------------------------------------------- 1 | 7 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhufengpeixun/vue-train/HEAD/day-3/vue-router-vux/src/assets/logo.png -------------------------------------------------------------------------------- /day-1/vue-jwt/src/views/Home.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/entry-compiler.js: -------------------------------------------------------------------------------- 1 | export { compile } from 'weex/compiler/index' 2 | export { generateCodeFrame } from 'compiler/codeframe' 3 | -------------------------------------------------------------------------------- /day-3/src/core/vdom/modules/index.js: -------------------------------------------------------------------------------- 1 | import directives from './directives' 2 | import ref from './ref' 3 | 4 | export default [ 5 | ref, 6 | directives 7 | ] 8 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/server/directives/index.js: -------------------------------------------------------------------------------- 1 | import show from './show' 2 | import model from './model' 3 | 4 | export default { 5 | show, 6 | model 7 | } 8 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/runtime/directives/index.js: -------------------------------------------------------------------------------- 1 | import model from './model' 2 | import show from './show' 3 | 4 | export default { 5 | model, 6 | show 7 | } 8 | -------------------------------------------------------------------------------- /day-3/src/core/vdom/helpers/is-async-placeholder.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export function isAsyncPlaceholder (node: VNode): boolean { 4 | return node.isComment && node.asyncFactory 5 | } 6 | -------------------------------------------------------------------------------- /day-2/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{js,jsx,ts,tsx,vue}] 2 | indent_style = space 3 | indent_size = 2 4 | end_of_line = lf 5 | trim_trailing_whitespace = true 6 | insert_final_newline = true 7 | max_line_length = 100 8 | -------------------------------------------------------------------------------- /day-1/vue-jwt/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{js,jsx,ts,tsx,vue}] 2 | indent_style = space 3 | indent_size = 2 4 | end_of_line = lf 5 | trim_trailing_whitespace = true 6 | insert_final_newline = true 7 | max_line_length = 100 8 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/runtime/components/index.js: -------------------------------------------------------------------------------- 1 | import Transition from './transition' 2 | import TransitionGroup from './transition-group' 3 | 4 | export default { 5 | Transition, 6 | TransitionGroup 7 | } 8 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/compiler/directives/index.js: -------------------------------------------------------------------------------- 1 | import model from './model' 2 | import text from './text' 3 | import html from './html' 4 | 5 | export default { 6 | model, 7 | text, 8 | html 9 | } 10 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/compiler/modules/index.js: -------------------------------------------------------------------------------- 1 | import klass from './class' 2 | import style from './style' 3 | import model from './model' 4 | 5 | export default [ 6 | klass, 7 | style, 8 | model 9 | ] 10 | -------------------------------------------------------------------------------- /day-3/src/compiler/directives/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import on from './on' 4 | import bind from './bind' 5 | import { noop } from 'shared/util' 6 | 7 | export default { 8 | on, 9 | bind, 10 | cloak: noop 11 | } 12 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/entry-runtime-factory.js: -------------------------------------------------------------------------------- 1 | // this entry is built and wrapped with a factory function 2 | // used to generate a fresh copy of Vue for every Weex instance. 3 | 4 | import Vue from './runtime/index' 5 | 6 | exports.Vue = Vue 7 | -------------------------------------------------------------------------------- /day-2/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import App from './App.vue'; 3 | 4 | Vue.config.productionTip = false; 5 | 6 | // 代码规范校验 用的 yorkie => husky (.git hook)lint-staged 7 | new Vue({ 8 | render: h => h(App), 9 | }).$mount('#app'); 10 | -------------------------------------------------------------------------------- /day-1/vue-component/history1/components/Grandson2.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/runtime/text-node.js: -------------------------------------------------------------------------------- 1 | let latestNodeId = 1 2 | 3 | export default function TextNode (text) { 4 | this.instanceId = '' 5 | this.nodeId = latestNodeId++ 6 | this.parentNode = null 7 | this.nodeType = 3 8 | this.text = text 9 | } 10 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/compiler/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { baseOptions } from './options' 4 | import { createCompiler } from 'compiler/index' 5 | 6 | const { compile, compileToFunctions } = createCompiler(baseOptions) 7 | 8 | export { compile, compileToFunctions } 9 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/server/modules/index.js: -------------------------------------------------------------------------------- 1 | import attrs from './attrs' 2 | import domProps from './dom-props' 3 | import klass from './class' 4 | import style from './style' 5 | 6 | export default [ 7 | attrs, 8 | domProps, 9 | klass, 10 | style 11 | ] 12 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/runtime/components/index.js: -------------------------------------------------------------------------------- 1 | import Richtext from './richtext' 2 | import Transition from './transition' 3 | import TransitionGroup from './transition-group' 4 | 5 | export default { 6 | Richtext, 7 | Transition, 8 | TransitionGroup 9 | } 10 | -------------------------------------------------------------------------------- /day-3/src/compiler/parser/entity-decoder.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | let decoder 4 | 5 | export default { 6 | decode (html: string): string { 7 | decoder = decoder || document.createElement('div') 8 | decoder.innerHTML = html 9 | return decoder.textContent 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/compiler/directives/html.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { addProp } from 'compiler/helpers' 4 | 5 | export default function html (el: ASTElement, dir: ASTDirective) { 6 | if (dir.value) { 7 | addProp(el, 'innerHTML', `_s(${dir.value})`, dir) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/compiler/directives/text.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { addProp } from 'compiler/helpers' 4 | 5 | export default function text (el: ASTElement, dir: ASTDirective) { 6 | if (dir.value) { 7 | addProp(el, 'textContent', `_s(${dir.value})`, dir) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /day-4/src/main.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import App from './App.vue'; 3 | import router from './router'; 4 | import store from './store'; 5 | 6 | Vue.config.productionTip = false; 7 | 8 | new Vue({ 9 | router, 10 | store, 11 | render: (h) => h(App), 12 | }).$mount('#app'); 13 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/entry-compiler.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export { parseComponent } from 'sfc/parser' 4 | export { compile, compileToFunctions } from './compiler/index' 5 | export { ssrCompile, ssrCompileToFunctions } from './server/compiler' 6 | export { generateCodeFrame } from 'compiler/codeframe' 7 | -------------------------------------------------------------------------------- /day-2/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/runtime/components/transition.js: -------------------------------------------------------------------------------- 1 | // reuse same transition component logic from web 2 | export { 3 | transitionProps, 4 | extractTransitionData 5 | } from 'web/runtime/components/transition' 6 | 7 | import Transition from 'web/runtime/components/transition' 8 | 9 | export default Transition 10 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/runtime/modules/index.js: -------------------------------------------------------------------------------- 1 | import attrs from './attrs' 2 | import klass from './class' 3 | import events from './events' 4 | import style from './style' 5 | import transition from './transition' 6 | 7 | export default [ 8 | attrs, 9 | klass, 10 | events, 11 | style, 12 | transition 13 | ] 14 | -------------------------------------------------------------------------------- /day-4/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /day-1/vue-component/history2/components/ListItem.js: -------------------------------------------------------------------------------- 1 | export default { 2 | props:{ 3 | render:{ 4 | type:Function 5 | }, 6 | item:{ 7 | type:String 8 | } 9 | 10 | }, 11 | render(h){ // createElement 12 | return this.render(h,this.item) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /day-1/vue-jwt/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /day-3/src/core/util/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export * from 'shared/util' 4 | export * from './lang' 5 | export * from './env' 6 | export * from './options' 7 | export * from './debug' 8 | export * from './props' 9 | export * from './error' 10 | export * from './next-tick' 11 | export { defineReactive } from '../observer/index' 12 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/compiler/modules/index.js: -------------------------------------------------------------------------------- 1 | import klass from './class' 2 | import style from './style' 3 | import props from './props' 4 | import append from './append' 5 | import recycleList from './recycle-list/index' 6 | 7 | export default [ 8 | recycleList, 9 | klass, 10 | style, 11 | props, 12 | append 13 | ] 14 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /day-1/vue-component/history1/App.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /day-3/src/core/instance/render-helpers/resolve-filter.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { identity, resolveAsset } from 'core/util/index' 4 | 5 | /** 6 | * Runtime helper for resolving filters 7 | */ 8 | export function resolveFilter (id: string): Function { 9 | return resolveAsset(this.$options, 'filters', id, true) || identity 10 | } 11 | -------------------------------------------------------------------------------- /day-3/src/core/vdom/helpers/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export * from './merge-hook' 4 | export * from './extract-props' 5 | export * from './update-listeners' 6 | export * from './normalize-children' 7 | export * from './resolve-async-component' 8 | export * from './get-first-component-child' 9 | export * from './is-async-placeholder' 10 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /day-2/dist/Cascader.css: -------------------------------------------------------------------------------- 1 | .cascader{display:inline-block}.title{width:150px;height:30px;border:1px solid #ccc}.content{display:-webkit-box;display:-ms-flexbox;display:flex}.content-left{border:1px solid #ccc;min-height:150px;max-height:150px;overflow-y:scroll}.label{width:80px;padding-left:5px}.label:hover{background:#999;cursor:pointer}.title{line-height:30px} -------------------------------------------------------------------------------- /day-3/src/core/global-api/mixin.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { mergeOptions } from '../util/index' 4 | 5 | export function initMixin (Vue: GlobalAPI) { 6 | Vue.mixin = function (mixin: Object) { 7 | // mergeOptions 合并选项 如果重名的变成数组 [beforeCreater] 8 | this.options = mergeOptions(this.options, mixin) 9 | return this 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /day-1/vue-jwt/src/api/index.js: -------------------------------------------------------------------------------- 1 | import axios from '../lib/ajaxRequest'; 2 | // 全部是promise 3 | export const getTest = () => axios.request({ url: '/test' }); 4 | export const login = username => axios.request({ url: '/login', method: 'POST', data: { username } }); 5 | 6 | export const validate = () => axios.request({ url: '/validate' }); 7 | export default {}; 8 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/server/compiler.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { baseOptions } from '../compiler/options' 4 | import { createCompiler } from 'server/optimizing-compiler/index' 5 | 6 | const { compile, compileToFunctions } = createCompiler(baseOptions) 7 | 8 | export { 9 | compile as ssrCompile, 10 | compileToFunctions as ssrCompileToFunctions 11 | } 12 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/server/modules/class.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { escape } from '../util' 4 | import { genClassForVnode } from 'web/util/index' 5 | 6 | export default function renderClass (node: VNodeWithData): ?string { 7 | const classList = genClassForVnode(node) 8 | if (classList !== '') { 9 | return ` class="${escape(classList)}"` 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/runtime/modules/index.js: -------------------------------------------------------------------------------- 1 | import attrs from './attrs' 2 | import klass from './class' 3 | import events from './events' 4 | import domProps from './dom-props' 5 | import style from './style' 6 | import transition from './transition' 7 | 8 | export default [ 9 | attrs, 10 | klass, 11 | events, 12 | domProps, 13 | style, 14 | transition 15 | ] 16 | -------------------------------------------------------------------------------- /day-4/src/shims-tsx.d.ts: -------------------------------------------------------------------------------- 1 | import Vue, { VNode } from 'vue'; 2 | 3 | declare global { 4 | namespace JSX { 5 | // tslint:disable no-empty-interface 6 | interface Element extends VNode {} 7 | // tslint:disable no-empty-interface 8 | interface ElementClass extends Vue {} 9 | interface IntrinsicElements { 10 | [elem: string]: any; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /day-3/src/compiler/directives/bind.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export default function bind (el: ASTElement, dir: ASTDirective) { 4 | el.wrapData = (code: string) => { 5 | return `_b(${code},'${el.tag}',${dir.value},${ 6 | dir.modifiers && dir.modifiers.prop ? 'true' : 'false' 7 | }${ 8 | dir.modifiers && dir.modifiers.sync ? ',true' : '' 9 | })` 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /day-3/src/compiler/directives/on.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { warn } from 'core/util/index' 4 | 5 | export default function on (el: ASTElement, dir: ASTDirective) { 6 | if (process.env.NODE_ENV !== 'production' && dir.modifiers) { 7 | warn(`v-on without argument does not support modifiers.`) 8 | } 9 | el.wrapListeners = (code: string) => `_g(${code},${dir.value})` 10 | } 11 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/server/directives/show.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export default function show (node: VNodeWithData, dir: VNodeDirective) { 4 | if (!dir.value) { 5 | const style: any = node.data.style || (node.data.style = {}) 6 | if (Array.isArray(style)) { 7 | style.push({ display: 'none' }) 8 | } else { 9 | style.display = 'none' 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/src/App.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /day-2/dist/demo.html: -------------------------------------------------------------------------------- 1 | 2 | Cascader demo 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 |
12 | 13 | 20 | -------------------------------------------------------------------------------- /day-2/tests/unit/example.spec.js: -------------------------------------------------------------------------------- 1 | import { shallowMount } from '@vue/test-utils'; 2 | import HelloWorld from '@/components/HelloWorld.vue'; 3 | 4 | describe('HelloWorld.vue', () => { 5 | it('renders props.msg when passed', () => { 6 | const msg = 'new message'; 7 | const wrapper = shallowMount(HelloWorld, { 8 | propsData: { msg }, 9 | }); 10 | expect(wrapper.text()).toMatch(msg); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | import router from './router' 4 | import store from './store' 5 | import ElementUI from 'element-ui'; 6 | import 'element-ui/lib/theme-chalk/index.css'; 7 | Vue.use(ElementUI); 8 | 9 | Vue.config.productionTip = false 10 | 11 | new Vue({ 12 | router, 13 | store, // this.$store 14 | render: h => h(App) 15 | }).$mount('#app') 16 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/src/components/Menu.vue: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /day-2/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true, 5 | }, 6 | extends: [ 7 | 'plugin:vue/essential', 8 | '@vue/airbnb', 9 | ], 10 | rules: { 11 | 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', 12 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', 13 | }, 14 | parserOptions: { 15 | parser: 'babel-eslint', 16 | }, 17 | }; 18 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/entry-server-basic-renderer.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import modules from './server/modules/index' 4 | import directives from './server/directives/index' 5 | import { isUnaryTag, canBeLeftOpenTag } from './compiler/util' 6 | import { createBasicRenderer } from 'server/create-basic-renderer' 7 | 8 | export default createBasicRenderer({ 9 | modules, 10 | directives, 11 | isUnaryTag, 12 | canBeLeftOpenTag 13 | }) 14 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/compiler/modules/recycle-list/component-root.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { addAttr } from 'compiler/helpers' 4 | 5 | // mark component root nodes as 6 | export function postTransformComponentRoot (el: ASTElement) { 7 | if (!el.parent) { 8 | // component root 9 | addAttr(el, '@isComponentRoot', 'true') 10 | addAttr(el, '@templateId', '_uid') 11 | addAttr(el, '@componentProps', '$props || {}') 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/src/store.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Vuex from 'vuex' 3 | 4 | Vue.use(Vuex) 5 | 6 | export default new Vuex.Store({ 7 | state: { 8 | name:'zf' 9 | }, 10 | mutations: { 11 | setUsername(state){ 12 | state.name = 'zf 1' 13 | } 14 | }, 15 | actions: { 16 | setUsername(s){ 17 | console.log(s) 18 | setTimeout(()=>{ 19 | s.commit('setUsername') 20 | },1000) 21 | } 22 | } 23 | }) 24 | -------------------------------------------------------------------------------- /day-3/src/shared/constants.js: -------------------------------------------------------------------------------- 1 | export const SSR_ATTR = 'data-server-rendered' 2 | 3 | export const ASSET_TYPES = [ 4 | 'component', 5 | 'directive', 6 | 'filter' 7 | ] 8 | 9 | export const LIFECYCLE_HOOKS = [ 10 | 'beforeCreate', 11 | 'created', 12 | 'beforeMount', 13 | 'mounted', 14 | 'beforeUpdate', 15 | 'updated', 16 | 'beforeDestroy', 17 | 'destroyed', 18 | 'activated', 19 | 'deactivated', 20 | 'errorCaptured', 21 | 'serverPrefetch' 22 | ] 23 | -------------------------------------------------------------------------------- /day-4/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "warning", 3 | "extends": [ 4 | "tslint:recommended" 5 | ], 6 | "linterOptions": { 7 | "exclude": [ 8 | "node_modules/**" 9 | ] 10 | }, 11 | "rules": { 12 | "indent": [true, "spaces", 2], 13 | "interface-name": false, 14 | "no-consecutive-blank-lines": false, 15 | "object-literal-sort-keys": false, 16 | "ordered-imports": false, 17 | "quotemark": [true, "single"] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /day-1/vue-component/history2/components/List1.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | -------------------------------------------------------------------------------- /day-4/README.md: -------------------------------------------------------------------------------- 1 | # vue-ts 2 | 3 | ## Project setup 4 | ``` 5 | yarn install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | yarn run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | yarn run build 16 | ``` 17 | 18 | ### Run your tests 19 | ``` 20 | yarn run test 21 | ``` 22 | 23 | ### Lints and fixes files 24 | ``` 25 | yarn run lint 26 | ``` 27 | 28 | ### Customize configuration 29 | See [Configuration Reference](https://cli.vuejs.org/config/). 30 | -------------------------------------------------------------------------------- /day-4/src/store.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Vuex from 'vuex'; 3 | 4 | Vue.use(Vuex); 5 | import {ITodo} from './types/todo'; 6 | 7 | interface IList { 8 | lists: ITodo[]; 9 | } 10 | 11 | export default new Vuex.Store({ 12 | state: { 13 | lists: [ // 数据 14 | {text: '睡觉', complete: true}, 15 | {text: '吃饭', complete: false}, 16 | ], 17 | }, 18 | mutations: { 19 | hello() { 20 | console.log(12222); 21 | }, 22 | }, 23 | actions: { 24 | 25 | }, 26 | }); 27 | -------------------------------------------------------------------------------- /day-1/vue-jwt/README.md: -------------------------------------------------------------------------------- 1 | # vue-jwt 2 | 3 | ## Project setup 4 | ``` 5 | yarn install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | yarn run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | yarn run build 16 | ``` 17 | 18 | ### Run your tests 19 | ``` 20 | yarn run test 21 | ``` 22 | 23 | ### Lints and fixes files 24 | ``` 25 | yarn run lint 26 | ``` 27 | 28 | ### Customize configuration 29 | See [Configuration Reference](https://cli.vuejs.org/config/). 30 | -------------------------------------------------------------------------------- /day-3/src/core/vdom/helpers/get-first-component-child.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { isDef } from 'shared/util' 4 | import { isAsyncPlaceholder } from './is-async-placeholder' 5 | 6 | export function getFirstComponentChild (children: ?Array): ?VNode { 7 | if (Array.isArray(children)) { 8 | for (let i = 0; i < children.length; i++) { 9 | const c = children[i] 10 | if (isDef(c) && (isDef(c.componentOptions) || isAsyncPlaceholder(c))) { 11 | return c 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/README.md: -------------------------------------------------------------------------------- 1 | # auth-list 2 | 3 | ## Project setup 4 | ``` 5 | yarn install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | yarn run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | yarn run build 16 | ``` 17 | 18 | ### Run your tests 19 | ``` 20 | yarn run test 21 | ``` 22 | 23 | ### Lints and fixes files 24 | ``` 25 | yarn run lint 26 | ``` 27 | 28 | ### Customize configuration 29 | See [Configuration Reference](https://cli.vuejs.org/config/). 30 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/README.md: -------------------------------------------------------------------------------- 1 | # auth-list 2 | 3 | ## Project setup 4 | ``` 5 | yarn install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | yarn run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | yarn run build 16 | ``` 17 | 18 | ### Run your tests 19 | ``` 20 | yarn run test 21 | ``` 22 | 23 | ### Lints and fixes files 24 | ``` 25 | yarn run lint 26 | ``` 27 | 28 | ### Customize configuration 29 | See [Configuration Reference](https://cli.vuejs.org/config/). 30 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/runtime/patch.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import * as nodeOps from 'web/runtime/node-ops' 4 | import { createPatchFunction } from 'core/vdom/patch' 5 | import baseModules from 'core/vdom/modules/index' 6 | import platformModules from 'web/runtime/modules/index' 7 | 8 | // the directive module should be applied last, after all 9 | // built-in modules have been applied. 10 | const modules = platformModules.concat(baseModules) 11 | 12 | export const patch: Function = createPatchFunction({ nodeOps, modules }) 13 | -------------------------------------------------------------------------------- /day-1/vue-jwt/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true, 5 | }, 6 | extends: [ 7 | 'plugin:vue/essential', 8 | '@vue/airbnb', 9 | ], 10 | rules: { 11 | 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', 12 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', 13 | 'consistent-return': 'off', 14 | 'import/no-extraneous-dependencies': 'off', 15 | }, 16 | parserOptions: { 17 | parser: 'babel-eslint', 18 | }, 19 | }; 20 | -------------------------------------------------------------------------------- /day-1/vue-jwt/src/views/Login.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/compiler/modules/recycle-list/v-once.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers' 4 | 5 | function containVOnce (el: ASTElement): boolean { 6 | for (const attr in el.attrsMap) { 7 | if (/^v\-once$/i.test(attr)) { 8 | return true 9 | } 10 | } 11 | return false 12 | } 13 | 14 | export function preTransformVOnce (el: ASTElement) { 15 | if (containVOnce(el)) { 16 | getAndRemoveAttr(el, 'v-once', true) 17 | addRawAttr(el, '[[once]]', true) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/src/router.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from './vue-router' 3 | import Home from './views/Home.vue' 4 | import About from './views/About.vue' 5 | 6 | // use 方法 会调用install方法 7 | Vue.use(Router); 8 | export default new Router({ 9 | mode: 'hash', 10 | base: process.env.BASE_URL, 11 | routes: [ 12 | { 13 | path: '/', 14 | name: 'home', 15 | component: Home 16 | }, 17 | { 18 | path: '/about', 19 | name: 'about', 20 | component: About 21 | }, 22 | ] 23 | }) 24 | -------------------------------------------------------------------------------- /day-1/vue-component/history2/components/List.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/runtime/patch.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import * as nodeOps from 'weex/runtime/node-ops' 4 | import { createPatchFunction } from 'core/vdom/patch' 5 | import baseModules from 'core/vdom/modules/index' 6 | import platformModules from 'weex/runtime/modules/index' 7 | 8 | // the directive module should be applied last, after all 9 | // built-in modules have been applied. 10 | const modules = platformModules.concat(baseModules) 11 | 12 | export const patch: Function = createPatchFunction({ 13 | nodeOps, 14 | modules, 15 | LONG_LIST_THRESHOLD: 10 16 | }) 17 | -------------------------------------------------------------------------------- /day-3/src/server/util.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export const isJS = (file: string): boolean => /\.js(\?[^.]+)?$/.test(file) 4 | 5 | export const isCSS = (file: string): boolean => /\.css(\?[^.]+)?$/.test(file) 6 | 7 | export function createPromiseCallback () { 8 | let resolve, reject 9 | const promise: Promise = new Promise((_resolve, _reject) => { 10 | resolve = _resolve 11 | reject = _reject 12 | }) 13 | const cb = (err: Error, res?: string) => { 14 | if (err) return reject(err) 15 | resolve(res || '') 16 | } 17 | return { promise, cb } 18 | } 19 | -------------------------------------------------------------------------------- /day-2/README.md: -------------------------------------------------------------------------------- 1 | # vue-cascader 2 | 3 | ## Project setup 4 | ``` 5 | yarn install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | yarn run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | yarn run build 16 | ``` 17 | 18 | ### Run your tests 19 | ``` 20 | yarn run test 21 | ``` 22 | 23 | ### Lints and fixes files 24 | ``` 25 | yarn run lint 26 | ``` 27 | 28 | ### Run your unit tests 29 | ``` 30 | yarn run test:unit 31 | ``` 32 | 33 | ### Customize configuration 34 | See [Configuration Reference](https://cli.vuejs.org/config/). 35 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "auth-list", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build" 8 | }, 9 | "dependencies": { 10 | "axios": "^0.19.0", 11 | "core-js": "^2.6.5", 12 | "element-ui": "^2.11.1", 13 | "vue": "^2.6.10", 14 | "vue-router": "^3.0.3", 15 | "vuex": "^3.0.1" 16 | }, 17 | "devDependencies": { 18 | "@vue/cli-plugin-babel": "^3.10.0", 19 | "@vue/cli-service": "^3.10.0", 20 | "vue-template-compiler": "^2.6.10" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "auth-list", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build" 8 | }, 9 | "dependencies": { 10 | "axios": "^0.19.0", 11 | "core-js": "^2.6.5", 12 | "element-ui": "^2.11.1", 13 | "vue": "^2.6.10", 14 | "vue-router": "^3.0.3", 15 | "vuex": "^3.0.1" 16 | }, 17 | "devDependencies": { 18 | "@vue/cli-plugin-babel": "^3.10.0", 19 | "@vue/cli-service": "^3.10.0", 20 | "vue-template-compiler": "^2.6.10" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /day-1/vue-component/history2/components/LevelFunctional.js: -------------------------------------------------------------------------------- 1 | export default { 2 | props:{ 3 | t:{} 4 | }, 5 | render(h){ // createElement 6 | // html 以< 开头 { 7 | let tag = 'h'+this.t 8 | return {this.$slots.default} 9 | 10 | // h1 on-click={()=>{alert(1)}} style={{color:'red'}}>你好 11 | h('h1',{ 12 | on:{ 13 | click(){ 14 | alert(1) 15 | }, 16 | }, 17 | attrs:{ 18 | a:1 19 | } 20 | },[h('span',{},'你好')]) 21 | } 22 | } -------------------------------------------------------------------------------- /day-4/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | vue-ts 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /day-1/vue-jwt/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | vue-jwt 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /day-2/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | vue-cascader 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /day-3/src/core/util/perf.js: -------------------------------------------------------------------------------- 1 | import { inBrowser } from './env' 2 | 3 | export let mark 4 | export let measure 5 | 6 | if (process.env.NODE_ENV !== 'production') { 7 | const perf = inBrowser && window.performance 8 | /* istanbul ignore if */ 9 | if ( 10 | perf && 11 | perf.mark && 12 | perf.measure && 13 | perf.clearMarks && 14 | perf.clearMeasures 15 | ) { 16 | mark = tag => perf.mark(tag) 17 | measure = (name, startTag, endTag) => { 18 | perf.measure(name, startTag, endTag) 19 | perf.clearMarks(startTag) 20 | perf.clearMarks(endTag) 21 | // perf.clearMeasures(name) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/compiler/modules/recycle-list/component.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { addAttr } from 'compiler/helpers' 4 | import { RECYCLE_LIST_MARKER } from 'weex/util/index' 5 | 6 | // mark components as inside recycle-list so that we know we need to invoke 7 | // their special @render function instead of render in create-component.js 8 | export function postTransformComponent ( 9 | el: ASTElement, 10 | options: WeexCompilerOptions 11 | ) { 12 | // $flow-disable-line (we know isReservedTag is there) 13 | if (!options.isReservedTag(el.tag) && el.tag !== 'cell-slot') { 14 | addAttr(el, RECYCLE_LIST_MARKER, 'true') 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | auth-list 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/src/App.vue: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /day-1/vue-component/history1/components/Son2.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | auth-list 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /day-1/vue-component/history2/components/Level.vue: -------------------------------------------------------------------------------- 1 | 21 | 22 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/compiler/options.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { 4 | isPreTag, 5 | mustUseProp, 6 | isReservedTag, 7 | getTagNamespace 8 | } from '../util/index' 9 | 10 | import modules from './modules/index' 11 | import directives from './directives/index' 12 | import { genStaticKeys } from 'shared/util' 13 | import { isUnaryTag, canBeLeftOpenTag } from './util' 14 | 15 | export const baseOptions: CompilerOptions = { 16 | expectHTML: true, 17 | modules, 18 | directives, 19 | isPreTag, 20 | isUnaryTag, 21 | mustUseProp, 22 | canBeLeftOpenTag, 23 | isReservedTag, 24 | getTagNamespace, 25 | staticKeys: genStaticKeys(modules) 26 | } 27 | -------------------------------------------------------------------------------- /day-3/src/server/optimizing-compiler/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { parse } from 'compiler/parser/index' 4 | import { generate } from './codegen' 5 | import { optimize } from './optimizer' 6 | import { createCompilerCreator } from 'compiler/create-compiler' 7 | 8 | export const createCompiler = createCompilerCreator(function baseCompile ( 9 | template: string, 10 | options: CompilerOptions 11 | ): CompiledResult { 12 | const ast = parse(template.trim(), options) 13 | optimize(ast, options) 14 | const code = generate(ast, options) 15 | return { 16 | ast, 17 | render: code.render, 18 | staticRenderFns: code.staticRenderFns 19 | } 20 | }) 21 | -------------------------------------------------------------------------------- /day-4/src/App.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 32 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/util/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { warn } from 'core/util/index' 4 | 5 | export * from './attrs' 6 | export * from './class' 7 | export * from './element' 8 | 9 | /** 10 | * Query an element selector if it's not an element already. 11 | */ 12 | export function query (el: string | Element): Element { 13 | if (typeof el === 'string') { 14 | const selected = document.querySelector(el) 15 | if (!selected) { 16 | process.env.NODE_ENV !== 'production' && warn( 17 | 'Cannot find element: ' + el 18 | ) 19 | return document.createElement('div') 20 | } 21 | return selected 22 | } else { 23 | return el 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/compiler/modules/recycle-list/text.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { addAttr } from 'compiler/helpers' 4 | 5 | function genText (node: ASTNode) { 6 | const value = node.type === 3 7 | ? node.text 8 | : node.type === 2 9 | ? node.tokens.length === 1 10 | ? node.tokens[0] 11 | : node.tokens 12 | : '' 13 | return JSON.stringify(value) 14 | } 15 | 16 | export function postTransformText (el: ASTElement) { 17 | // weex can only contain text, so the parser 18 | // always generates a single child. 19 | if (el.children.length) { 20 | addAttr(el, 'value', genText(el.children[0])) 21 | el.children = [] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/src/components/MenuItem.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | -------------------------------------------------------------------------------- /day-4/src/router.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Router from 'vue-router'; 3 | import Home from './views/Home.vue'; 4 | 5 | Vue.use(Router); 6 | 7 | export default new Router({ 8 | mode: 'history', 9 | base: process.env.BASE_URL, 10 | routes: [ 11 | { 12 | path: '/', 13 | name: 'home', 14 | component: Home, 15 | }, 16 | { 17 | path: '/about', 18 | name: 'about', 19 | // route level code-splitting 20 | // this generates a separate chunk (about.[hash].js) for this route 21 | // which is lazy-loaded when the route is visited. 22 | component: () => import(/* webpackChunkName: "about" */ './views/About.vue'), 23 | }, 24 | ], 25 | }); 26 | -------------------------------------------------------------------------------- /day-1/vue-jwt/src/router.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Router from 'vue-router'; 3 | import Home from './views/Home.vue'; 4 | import Login from './views/Login.vue'; 5 | import Profile from './views/Profile.vue'; 6 | 7 | Vue.use(Router); 8 | 9 | export default new Router({ 10 | mode: 'history', 11 | base: process.env.BASE_URL, 12 | routes: [ 13 | { 14 | path: '/', 15 | name: 'home', 16 | component: Home, 17 | }, 18 | { 19 | path: '/login', 20 | name: 'login', 21 | component: Login, 22 | }, 23 | { 24 | path: '/profile', 25 | name: 'profile', 26 | component: Profile, 27 | meta: { needLogin: true }, // 自己增加的备注 28 | }, 29 | ], 30 | }); 31 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/util/compat.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { inBrowser } from 'core/util/index' 4 | 5 | // check whether current browser encodes a char inside attribute values 6 | let div 7 | function getShouldDecode (href: boolean): boolean { 8 | div = div || document.createElement('div') 9 | div.innerHTML = href ? `` : `
` 10 | return div.innerHTML.indexOf(' ') > 0 11 | } 12 | 13 | // #3663: IE encodes newlines inside attribute values while other browsers don't 14 | export const shouldDecodeNewlines = inBrowser ? getShouldDecode(false) : false 15 | // #6828: chrome encodes content in a[href] 16 | export const shouldDecodeNewlinesForHref = inBrowser ? getShouldDecode(true) : false 17 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | import router from './router' 4 | import store from './store' 5 | import ElementUI from 'element-ui'; 6 | import 'element-ui/lib/theme-chalk/index.css'; 7 | Vue.use(ElementUI); 8 | 9 | Vue.config.productionTip = false 10 | 11 | router.beforeEach(async (to,from,next)=>{ 12 | if(!store.state.hasPermission){ // 如果没权限 需要获取权限 13 | // 获取需要添加的路由 14 | let newRoutes = await store.dispatch('getNewRoute'); 15 | // 动态添加路由 16 | router.addRoutes(newRoutes); // 动态添加我需要的路由 17 | next({...to}); // replaceState 18 | }else{ 19 | next(); 20 | } 21 | }) 22 | new Vue({ 23 | router, 24 | store, 25 | render: h => h(App) 26 | }).$mount('#app') 27 | -------------------------------------------------------------------------------- /day-3/src/core/instance/render-helpers/bind-object-listeners.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { warn, extend, isPlainObject } from 'core/util/index' 4 | 5 | export function bindObjectListeners (data: any, value: any): VNodeData { 6 | if (value) { 7 | if (!isPlainObject(value)) { 8 | process.env.NODE_ENV !== 'production' && warn( 9 | 'v-on without argument expects an Object value', 10 | this 11 | ) 12 | } else { 13 | const on = data.on = data.on ? extend({}, data.on) : {} 14 | for (const key in value) { 15 | const existing = on[key] 16 | const ours = value[key] 17 | on[key] = existing ? [].concat(existing, ours) : ours 18 | } 19 | } 20 | } 21 | return data 22 | } 23 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/compiler/modules/recycle-list/v-bind.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { camelize } from 'shared/util' 4 | import { generateBinding } from 'weex/util/parser' 5 | import { bindRE } from 'compiler/parser/index' 6 | import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers' 7 | 8 | function parseAttrName (name: string): string { 9 | return camelize(name.replace(bindRE, '')) 10 | } 11 | 12 | export function preTransformVBind (el: ASTElement) { 13 | for (const attr in el.attrsMap) { 14 | if (bindRE.test(attr)) { 15 | const name: string = parseAttrName(attr) 16 | const value = generateBinding(getAndRemoveAttr(el, attr)) 17 | delete el.attrsMap[attr] 18 | addRawAttr(el, name, value) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /day-1/vue-component/history1/components/Son1.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | -------------------------------------------------------------------------------- /day-2/src/directives/clickOutside.js: -------------------------------------------------------------------------------- 1 | 2 | // const listener = function (e) { 3 | // return (el, bindings) => { 4 | // if (e.target === el || el.contains(e.target)) { 5 | // return; 6 | // } 7 | // bindings.value(); // close事件 8 | // }; 9 | // }; 10 | 11 | export default { // 指令是一个方法 指令有自己的生命周期 12 | // bind update 13 | 14 | clickOutside: { 15 | inserted(el, bindings) { // el真实的dom元素 16 | el.listener = function listener(e) { 17 | if (e.target === el || el.contains(e.target)) { 18 | return; 19 | } 20 | bindings.value(); // close事件 21 | }; 22 | document.addEventListener('click', el.listener); 23 | }, 24 | unbind(el) { 25 | document.removeEventListener('click', el.listener); 26 | }, 27 | }, 28 | }; 29 | -------------------------------------------------------------------------------- /day-3/src/core/global-api/use.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { toArray } from '../util/index' 4 | Vue.use(xxx,'123','123') 5 | export function initUse (Vue: GlobalAPI) { // 调用install方法 第一和参数 Vue 6 | Vue.use = function (plugin: Function | Object) { 7 | const installedPlugins = (this._installedPlugins || (this._installedPlugins = [])) 8 | if (installedPlugins.indexOf(plugin) > -1) { 9 | return this 10 | } 11 | 12 | // additional parameters 13 | const args = toArray(arguments, 1) 14 | args.unshift(this) 15 | if (typeof plugin.install === 'function') { 16 | plugin.install.apply(plugin, args) // 17 | } else if (typeof plugin === 'function') { 18 | plugin.apply(null, args) 19 | } 20 | installedPlugins.push(plugin) 21 | return this 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /day-3/src/core/index.js: -------------------------------------------------------------------------------- 1 | import Vue from './instance/index' 2 | import { initGlobalAPI } from './global-api/index' 3 | import { isServerRendering } from 'core/util/env' 4 | import { FunctionalRenderContext } from 'core/vdom/create-functional-component' 5 | 6 | initGlobalAPI(Vue) 7 | 8 | Object.defineProperty(Vue.prototype, '$isServer', { 9 | get: isServerRendering 10 | }) 11 | 12 | Object.defineProperty(Vue.prototype, '$ssrContext', { 13 | get () { 14 | /* istanbul ignore next */ 15 | return this.$vnode && this.$vnode.ssrContext 16 | } 17 | }) 18 | 19 | // expose FunctionalRenderContext for ssr runtime helper installation 20 | Object.defineProperty(Vue, 'FunctionalRenderContext', { 21 | value: FunctionalRenderContext 22 | }) 23 | 24 | Vue.version = '__VERSION__' 25 | 26 | export default Vue 27 | -------------------------------------------------------------------------------- /day-2/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | moduleFileExtensions: [ 3 | 'js', 4 | 'jsx', 5 | 'json', 6 | 'vue', 7 | ], 8 | transform: { 9 | '^.+\\.vue$': 'vue-jest', 10 | '.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub', 11 | '^.+\\.jsx?$': 'babel-jest', 12 | }, 13 | transformIgnorePatterns: [ 14 | '/node_modules/', 15 | ], 16 | moduleNameMapper: { 17 | '^@/(.*)$': '/src/$1', 18 | }, 19 | snapshotSerializers: [ 20 | 'jest-serializer-vue', 21 | ], 22 | testMatch: [ 23 | '**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)', 24 | ], 25 | testURL: 'http://localhost/', 26 | watchPlugins: [ 27 | 'jest-watch-typeahead/filename', 28 | 'jest-watch-typeahead/testname', 29 | ], 30 | }; 31 | -------------------------------------------------------------------------------- /day-4/src/components/TodoItem.tsx: -------------------------------------------------------------------------------- 1 | import { Component, Vue , Prop, Emit, Watch} from 'vue-property-decorator'; 2 | import {ITodo} from '../types/todo'; 3 | // Vue.extend 4 | @Component 5 | export default class TodoItem extends Vue { 6 | public i: number = 1; 7 | @Prop(Object) public item !: ITodo; // 强制认为是对象类型 8 | @Prop(Number) public index!: number; 9 | @Emit('say') 10 | public say1() { 11 | return 'hello'; 12 | } 13 | @Watch('i') 14 | public fn() { 15 | console.log('i变化了'); 16 | } 17 | public increment() { 18 | this.i += 1; 19 | } 20 | protected render() { 21 | return

{this.item.text} 22 | {this.i} 23 | 24 |

; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /day-3/src/core/instance/index.js: -------------------------------------------------------------------------------- 1 | import { initMixin } from './init' 2 | import { stateMixin } from './state' 3 | import { renderMixin } from './render' 4 | import { eventsMixin } from './events' 5 | import { lifecycleMixin } from './lifecycle' 6 | import { warn } from '../util/index' 7 | 8 | function Vue (options) { 9 | if (process.env.NODE_ENV !== 'production' && 10 | !(this instanceof Vue) 11 | ) { 12 | warn('Vue is a constructor and should be called with the `new` keyword') 13 | } 14 | this._init(options); // 一使用vue 就会调用init方法 15 | } 16 | // 给当前实例添加属性 和 方法 17 | initMixin(Vue) // 初始化mixin 18 | stateMixin(Vue) // $set $delete $watch 19 | eventsMixin(Vue) // 实现vue的发布订阅模式 20 | lifecycleMixin(Vue) // Vue.prototype._update $forceUpdate $destroy 21 | renderMixin(Vue) // Vue.prototype._render 22 | 23 | export default Vue 24 | -------------------------------------------------------------------------------- /day-1/vue-jwt/src/App.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 17 | 18 | 19 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/compiler/modules/append.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { makeMap } from 'shared/util' 4 | 5 | // The "unitary tag" means that the tag node and its children 6 | // must be sent to the native together. 7 | const isUnitaryTag = makeMap('cell,header,cell-slot,recycle-list', true) 8 | 9 | function preTransformNode (el: ASTElement) { 10 | if (isUnitaryTag(el.tag) && !el.attrsList.some(item => item.name === 'append')) { 11 | el.attrsMap.append = 'tree' 12 | el.attrsList.push({ name: 'append', value: 'tree' }) 13 | } 14 | if (el.attrsMap.append === 'tree') { 15 | el.appendAsTree = true 16 | } 17 | } 18 | 19 | function genData (el: ASTElement): string { 20 | return el.appendAsTree ? `appendAsTree:true,` : '' 21 | } 22 | 23 | export default { 24 | staticKeys: ['appendAsTree'], 25 | preTransformNode, 26 | genData 27 | } 28 | -------------------------------------------------------------------------------- /day-4/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "strict": true, 6 | "jsx": "preserve", 7 | "importHelpers": true, 8 | "moduleResolution": "node", 9 | "experimentalDecorators": true, 10 | "esModuleInterop": true, 11 | "allowSyntheticDefaultImports": true, 12 | "sourceMap": true, 13 | "baseUrl": ".", 14 | "types": [ 15 | "webpack-env" 16 | ], 17 | "paths": { 18 | "@/*": [ 19 | "src/*" 20 | ] 21 | }, 22 | "lib": [ 23 | "esnext", 24 | "dom", 25 | "dom.iterable", 26 | "scripthost" 27 | ] 28 | }, 29 | "include": [ 30 | "src/**/*.ts", 31 | "src/**/*.tsx", 32 | "src/**/*.vue", 33 | "tests/**/*.ts", 34 | "tests/**/*.tsx" 35 | ], 36 | "exclude": [ 37 | "node_modules" 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/compiler/modules/recycle-list/v-on.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | const inlineStatementRE = /^\s*([A-Za-z_$0-9\['\."\]]+)*\s*\(\s*(([A-Za-z_$0-9\['\."\]]+)?(\s*,\s*([A-Za-z_$0-9\['\."\]]+))*)\s*\)$/ 4 | 5 | function parseHandlerParams (handler: ASTElementHandler) { 6 | const res = inlineStatementRE.exec(handler.value) 7 | if (res && res[2]) { 8 | handler.params = res[2].split(/\s*,\s*/) 9 | } 10 | } 11 | 12 | export function postTransformVOn (el: ASTElement) { 13 | const events: ASTElementHandlers | void = el.events 14 | if (!events) { 15 | return 16 | } 17 | for (const name in events) { 18 | const handler: ASTElementHandler | Array = events[name] 19 | if (Array.isArray(handler)) { 20 | handler.map(fn => parseHandlerParams(fn)) 21 | } else { 22 | parseHandlerParams(handler) 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /day-3/src/core/instance/render-helpers/resolve-scoped-slots.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | export function resolveScopedSlots ( 4 | fns: ScopedSlotsData, // see flow/vnode 5 | res?: Object, 6 | // the following are added in 2.6 7 | hasDynamicKeys?: boolean, 8 | contentHashKey?: number 9 | ): { [key: string]: Function, $stable: boolean } { 10 | res = res || { $stable: !hasDynamicKeys } 11 | for (let i = 0; i < fns.length; i++) { 12 | const slot = fns[i] 13 | if (Array.isArray(slot)) { 14 | resolveScopedSlots(slot, res, hasDynamicKeys) 15 | } else if (slot) { 16 | // marker for reverse proxying v-slot without scope on this.$slots 17 | if (slot.proxy) { 18 | slot.fn.proxy = true 19 | } 20 | res[slot.key] = slot.fn 21 | } 22 | } 23 | if (contentHashKey) { 24 | (res: any).$key = contentHashKey 25 | } 26 | return res 27 | } 28 | -------------------------------------------------------------------------------- /day-3/src/compiler/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { parse } from './parser/index' 4 | import { optimize } from './optimizer' 5 | import { generate } from './codegen/index' 6 | import { createCompilerCreator } from './create-compiler' 7 | 8 | // `createCompilerCreator` allows creating compilers that use alternative 9 | // parser/optimizer/codegen, e.g the SSR optimizing compiler. 10 | // Here we just export a default compiler using the default parts. 11 | export const createCompiler = createCompilerCreator(function baseCompile ( 12 | template: string, 13 | options: CompilerOptions 14 | ): CompiledResult { 15 | const ast = parse(template.trim(), options) 16 | if (options.optimize !== false) { 17 | optimize(ast, options) 18 | } 19 | const code = generate(ast, options) 20 | return { 21 | ast, 22 | render: code.render, 23 | staticRenderFns: code.staticRenderFns 24 | } 25 | }) 26 | -------------------------------------------------------------------------------- /day-1/vue-jwt/src/store.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Vuex from 'vuex'; 3 | import { login, validate } from './api'; 4 | 5 | Vue.use(Vuex); 6 | 7 | export default new Vuex.Store({ 8 | state: { 9 | username: '', 10 | }, 11 | mutations: { 12 | setUsername(state, username) { 13 | state.username = username; 14 | }, 15 | }, 16 | actions: { 17 | async validate({ commit }) { 18 | const r = await validate(); 19 | if (r.code === 1) { 20 | return false; 21 | } 22 | commit('setUsername', r.username); 23 | localStorage.setItem('token', r.token); 24 | return true; 25 | }, 26 | async login({ commit }, username) { 27 | const r = await login(username); 28 | if (r.code === 1) { 29 | return Promise.reject(r); 30 | } 31 | localStorage.setItem('token', r.token); 32 | commit('setUsername', r.username); 33 | }, 34 | }, 35 | }); 36 | -------------------------------------------------------------------------------- /day-4/src/views/Home.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 37 | -------------------------------------------------------------------------------- /day-1/vue-component/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import App from './App'; 3 | import iView from 'iview'; 4 | import 'iview/dist/styles/iview.css'; 5 | Vue.use(iView) 6 | Vue.prototype.$bus = new Vue(); // $on $emit 7 | // 向上通知 8 | Vue.prototype.$dispatch = function(eventName,value){ 9 | let parent = this.$parent; 10 | while(parent){ 11 | parent.$emit(eventName,value); 12 | parent = parent.$parent 13 | } 14 | } 15 | // 向下传递 16 | Vue.prototype.$broadcast = function(eventName,value){ 17 | // 获取当前组件下的所有的孩子 18 | const broadcast = (children) =>{ 19 | children.forEach(child => { 20 | child.$emit(eventName,value); 21 | if(child.$children){ 22 | broadcast(child.$children); 23 | } 24 | }); 25 | } 26 | broadcast(this.$children); 27 | 28 | } 29 | const vm = new Vue({ 30 | el:'#app', 31 | render:h=> h(App) 32 | }) 33 | // 组件间通信 34 | // 构建 通信组件 -------------------------------------------------------------------------------- /day-3/src/platforms/weex/compiler/modules/recycle-list/v-for.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { parseFor } from 'compiler/parser/index' 4 | import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers' 5 | 6 | export function preTransformVFor (el: ASTElement, options: WeexCompilerOptions) { 7 | const exp = getAndRemoveAttr(el, 'v-for') 8 | if (!exp) { 9 | return 10 | } 11 | 12 | const res = parseFor(exp) 13 | if (!res) { 14 | if (process.env.NODE_ENV !== 'production' && options.warn) { 15 | options.warn(`Invalid v-for expression: ${exp}`) 16 | } 17 | return 18 | } 19 | 20 | const desc: Object = { 21 | '@expression': res.for, 22 | '@alias': res.alias 23 | } 24 | if (res.iterator2) { 25 | desc['@key'] = res.iterator1 26 | desc['@index'] = res.iterator2 27 | } else { 28 | desc['@index'] = res.iterator1 29 | } 30 | 31 | delete el.attrsMap['v-for'] 32 | addRawAttr(el, '[[repeat]]', desc) 33 | } 34 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/src/vuex.js: -------------------------------------------------------------------------------- 1 | let Vue; 2 | class Store{ 3 | constructor(options){ 4 | this.vm = new Vue({ // new Vue 会创建vue的实例 将状态变成响应式的 如果数据更新 则试图刷新 5 | data:{state:options.state} 6 | }); 7 | this.state = this.vm.state 8 | this.mutations = options.mutations; 9 | this.actions = options.actions; 10 | } 11 | commit = (eventName)=>{ 12 | this.mutations[eventName](this.state) 13 | } 14 | dispatch = (eventName) =>{ 15 | this.actions[eventName](this); 16 | } 17 | } 18 | const install = (_Vue)=>{ 19 | Vue = _Vue; 20 | Vue.mixin({ 21 | beforeCreate(){ 22 | if(this.$options && this.$options.store){ 23 | this.$store = this.$options.store 24 | }else{ 25 | this.$store = this.$parent && this.$parent.$store 26 | } 27 | } 28 | }) 29 | } 30 | export default { 31 | Store, 32 | install 33 | } -------------------------------------------------------------------------------- /day-1/vue-component/history1/components/Grandson1.vue: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /day-3/src/server/create-basic-renderer.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { createWriteFunction } from './write' 4 | import { createRenderFunction } from './render' 5 | import type { RenderOptions } from './create-renderer' 6 | 7 | export function createBasicRenderer ({ 8 | modules = [], 9 | directives = {}, 10 | isUnaryTag = (() => false), 11 | cache 12 | }: RenderOptions = {}) { 13 | const render = createRenderFunction(modules, directives, isUnaryTag, cache) 14 | 15 | return function renderToString ( 16 | component: Component, 17 | context: any, 18 | done: any 19 | ): void { 20 | if (typeof context === 'function') { 21 | done = context 22 | context = {} 23 | } 24 | let result = '' 25 | const write = createWriteFunction(text => { 26 | result += text 27 | return false 28 | }, done) 29 | try { 30 | render(component, write, context, () => { 31 | done(null, result) 32 | }) 33 | } catch (e) { 34 | done(e) 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/compiler/util.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { makeMap } from 'shared/util' 4 | 5 | export const isUnaryTag = makeMap( 6 | 'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' + 7 | 'link,meta,param,source,track,wbr' 8 | ) 9 | 10 | // Elements that you can, intentionally, leave open 11 | // (and which close themselves) 12 | export const canBeLeftOpenTag = makeMap( 13 | 'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source' 14 | ) 15 | 16 | // HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3 17 | // Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content 18 | export const isNonPhrasingTag = makeMap( 19 | 'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' + 20 | 'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' + 21 | 'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' + 22 | 'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' + 23 | 'title,tr,track' 24 | ) 25 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/entry-server-renderer.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | process.env.VUE_ENV = 'server' 4 | 5 | import { extend } from 'shared/util' 6 | import modules from './server/modules/index' 7 | import baseDirectives from './server/directives/index' 8 | import { isUnaryTag, canBeLeftOpenTag } from './compiler/util' 9 | 10 | import { createRenderer as _createRenderer } from 'server/create-renderer' 11 | import { createBundleRendererCreator } from 'server/bundle-renderer/create-bundle-renderer' 12 | 13 | export function createRenderer (options?: Object = {}): { 14 | renderToString: Function, 15 | renderToStream: Function 16 | } { 17 | return _createRenderer(extend(extend({}, options), { 18 | isUnaryTag, 19 | canBeLeftOpenTag, 20 | modules, 21 | // user can provide server-side implementations for custom directives 22 | // when creating the renderer. 23 | directives: extend(baseDirectives, options.directives) 24 | })) 25 | } 26 | 27 | export const createBundleRenderer = createBundleRendererCreator(createRenderer) 28 | -------------------------------------------------------------------------------- /day-4/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-ts", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "core-js": "^2.6.5", 12 | "vue": "^2.6.10", 13 | "vue-class-component": "^7.0.2", 14 | "vue-property-decorator": "^8.1.0", 15 | "vue-router": "^3.0.3", 16 | "vuex": "^3.0.1", 17 | "vuex-class": "^0.3.2" 18 | }, 19 | "devDependencies": { 20 | "@vue/cli-plugin-babel": "^3.10.0", 21 | "@vue/cli-plugin-typescript": "^3.10.0", 22 | "@vue/cli-service": "^3.10.0", 23 | "lint-staged": "^8.1.5", 24 | "typescript": "^3.4.3", 25 | "vue-template-compiler": "^2.6.10" 26 | }, 27 | "gitHooks": { 28 | "pre-commit": "lint-staged" 29 | }, 30 | "lint-staged": { 31 | "*.ts": [ 32 | "vue-cli-service lint", 33 | "git add" 34 | ], 35 | "*.vue": [ 36 | "vue-cli-service lint", 37 | "git add" 38 | ] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/compiler/directives/model.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { addHandler, addAttr } from 'compiler/helpers' 4 | import { genComponentModel, genAssignmentCode } from 'compiler/directives/model' 5 | 6 | export default function model ( 7 | el: ASTElement, 8 | dir: ASTDirective 9 | ): ?boolean { 10 | if (el.tag === 'input' || el.tag === 'textarea') { 11 | genDefaultModel(el, dir.value, dir.modifiers) 12 | } else { 13 | genComponentModel(el, dir.value, dir.modifiers) 14 | } 15 | } 16 | 17 | function genDefaultModel ( 18 | el: ASTElement, 19 | value: string, 20 | modifiers: ?ASTModifiers 21 | ): ?boolean { 22 | const { lazy, trim, number } = modifiers || {} 23 | const event = lazy ? 'change' : 'input' 24 | 25 | let valueExpression = `$event.target.attr.value${trim ? '.trim()' : ''}` 26 | if (number) { 27 | valueExpression = `_n(${valueExpression})` 28 | } 29 | 30 | const code = genAssignmentCode(value, valueExpression) 31 | addAttr(el, 'value', `(${value})`) 32 | addHandler(el, event, code, null, true) 33 | } 34 | -------------------------------------------------------------------------------- /day-1/vue-jwt/src/lib/ajaxRequest.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | 4 | // 每个请求的拦截器方法可能不一样 5 | 6 | class AjaxRequest { 7 | constructor() { 8 | this.baseURL = process.env.NODE_ENV === 'development' ? 'http://localhost:3000' : '/'; 9 | this.timeout = 2000; 10 | } 11 | 12 | request(config) { // 用户请求设置的方法 13 | const instance = axios.create({ 14 | baseURL: this.baseURL, 15 | timeout: this.timeout, 16 | }); 17 | // 设置拦截器 18 | instance.interceptors.request.use((config) => { 19 | console.log(1); 20 | config.headers.Authorization = localStorage.getItem('token'); 21 | return config; 22 | }, err => Promise.reject(err)); 23 | instance.interceptors.request.use((config) => { 24 | config.headers.Authorization = localStorage.getItem('token'); 25 | return config; 26 | }, err => Promise.reject(err)); 27 | // 设置响应拦截器 28 | instance.interceptors.response.use(res => res.data, err => Promise.reject(err)); 29 | 30 | return instance(config); 31 | } 32 | } 33 | 34 | export default new AjaxRequest(); 35 | -------------------------------------------------------------------------------- /day-3/vue-router-vux/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | 3 | const app = express(); 4 | app.all('*', (req, res, next) => { 5 | res.header('Access-Control-Allow-Origin', '*'); 6 | // Access-Control-Allow-Headers ,可根据浏览器的F12查看,把对应的粘贴在这里就行 7 | res.header('Access-Control-Allow-Headers', 'Content-Type'); 8 | res.header('Access-Control-Allow-Methods', '*'); 9 | res.header('Content-Type', 'application/json;charset=utf-8'); 10 | next(); 11 | }); 12 | app.get('/roleAuth', (req, res) => { 13 | res.json({ 14 | menuList: [ 15 | { 16 | pid: -1, 17 | name: '购物车', 18 | id: 1, 19 | auth: 'cart', 20 | }, 21 | { 22 | pid: 1, 23 | name: '购物车列表', 24 | id: 4, 25 | auth: 'cart-list', 26 | }, 27 | { 28 | pid: 4, 29 | name: '彩票', 30 | id: 5, 31 | auth: 'lottery', 32 | }, 33 | { 34 | pid: 4, 35 | name: '商品', 36 | id: 6, 37 | auth: 'product', 38 | }, 39 | ], 40 | }); 41 | }); 42 | app.listen(3000); 43 | -------------------------------------------------------------------------------- /day-3/src/core/instance/render-helpers/render-slot.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { extend, warn, isObject } from 'core/util/index' 4 | 5 | /** 6 | * Runtime helper for rendering 7 | */ 8 | export function renderSlot ( 9 | name: string, 10 | fallback: ?Array, 11 | props: ?Object, 12 | bindObject: ?Object 13 | ): ?Array { 14 | const scopedSlotFn = this.$scopedSlots[name] 15 | let nodes 16 | if (scopedSlotFn) { // scoped slot 17 | props = props || {} 18 | if (bindObject) { 19 | if (process.env.NODE_ENV !== 'production' && !isObject(bindObject)) { 20 | warn( 21 | 'slot v-bind without argument expects an Object', 22 | this 23 | ) 24 | } 25 | props = extend(extend({}, bindObject), props) 26 | } 27 | nodes = scopedSlotFn(props) || fallback 28 | } else { 29 | nodes = this.$slots[name] || fallback 30 | } 31 | 32 | const target = props && props.slot 33 | if (target) { 34 | return this.$createElement('template', { slot: target }, nodes) 35 | } else { 36 | return nodes 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | 3 | const app = express(); 4 | app.all('*', (req, res, next) => { 5 | res.header('Access-Control-Allow-Origin', '*'); 6 | // Access-Control-Allow-Headers ,可根据浏览器的F12查看,把对应的粘贴在这里就行 7 | res.header('Access-Control-Allow-Headers', 'Content-Type'); 8 | res.header('Access-Control-Allow-Methods', '*'); 9 | res.header('Content-Type', 'application/json;charset=utf-8'); 10 | next(); 11 | }); 12 | app.get('/roleAuth', (req, res) => { 13 | res.json({ 14 | menuList: [ 15 | { 16 | pid: -1, 17 | name: '购物车', 18 | id: 1, 19 | auth: 'cart', 20 | }, 21 | // { 22 | // pid: 1, 23 | // name: '购物车列表', 24 | // id: 4, 25 | // auth: 'cart-list', 26 | // }, 27 | // { 28 | // pid: 4, 29 | // name: '彩票', 30 | // id: 5, 31 | // auth: 'lottery', 32 | // }, 33 | { 34 | pid: 4, 35 | name: '商品', 36 | id: 6, 37 | auth: 'product', 38 | }, 39 | ], 40 | }); 41 | }); 42 | app.listen(3000); 43 | -------------------------------------------------------------------------------- /day-3/src/core/observer/traverse.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { _Set as Set, isObject } from '../util/index' 4 | import type { SimpleSet } from '../util/index' 5 | import VNode from '../vdom/vnode' 6 | 7 | const seenObjects = new Set() 8 | 9 | /** 10 | * Recursively traverse an object to evoke all converted 11 | * getters, so that every nested property inside the object 12 | * is collected as a "deep" dependency. 13 | */ 14 | export function traverse (val: any) { 15 | _traverse(val, seenObjects) 16 | seenObjects.clear() 17 | } 18 | 19 | function _traverse (val: any, seen: SimpleSet) { 20 | let i, keys 21 | const isA = Array.isArray(val) 22 | if ((!isA && !isObject(val)) || Object.isFrozen(val) || val instanceof VNode) { 23 | return 24 | } 25 | if (val.__ob__) { 26 | const depId = val.__ob__.dep.id 27 | if (seen.has(depId)) { 28 | return 29 | } 30 | seen.add(depId) 31 | } 32 | if (isA) { 33 | i = val.length 34 | while (i--) _traverse(val[i], seen) 35 | } else { 36 | keys = Object.keys(val) 37 | i = keys.length 38 | while (i--) _traverse(val[keys[i]], seen) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/runtime/modules/class.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { 4 | isDef, 5 | isUndef 6 | } from 'shared/util' 7 | 8 | import { 9 | concat, 10 | stringifyClass, 11 | genClassForVnode 12 | } from 'web/util/index' 13 | 14 | function updateClass (oldVnode: any, vnode: any) { 15 | const el = vnode.elm 16 | const data: VNodeData = vnode.data 17 | const oldData: VNodeData = oldVnode.data 18 | if ( 19 | isUndef(data.staticClass) && 20 | isUndef(data.class) && ( 21 | isUndef(oldData) || ( 22 | isUndef(oldData.staticClass) && 23 | isUndef(oldData.class) 24 | ) 25 | ) 26 | ) { 27 | return 28 | } 29 | 30 | let cls = genClassForVnode(vnode) 31 | 32 | // handle transition classes 33 | const transitionClass = el._transitionClasses 34 | if (isDef(transitionClass)) { 35 | cls = concat(cls, stringifyClass(transitionClass)) 36 | } 37 | 38 | // set the class 39 | if (cls !== el._prevClass) { 40 | el.setAttribute('class', cls) 41 | el._prevClass = cls 42 | } 43 | } 44 | 45 | export default { 46 | create: updateClass, 47 | update: updateClass 48 | } 49 | -------------------------------------------------------------------------------- /day-3/src/server/webpack-plugin/util.js: -------------------------------------------------------------------------------- 1 | const { red, yellow } = require('chalk') 2 | 3 | const prefix = `[vue-server-renderer-webpack-plugin]` 4 | const warn = exports.warn = msg => console.error(red(`${prefix} ${msg}\n`)) 5 | const tip = exports.tip = msg => console.log(yellow(`${prefix} ${msg}\n`)) 6 | 7 | export const validate = compiler => { 8 | if (compiler.options.target !== 'node') { 9 | warn('webpack config `target` should be "node".') 10 | } 11 | 12 | if (compiler.options.output && compiler.options.output.libraryTarget !== 'commonjs2') { 13 | warn('webpack config `output.libraryTarget` should be "commonjs2".') 14 | } 15 | 16 | if (!compiler.options.externals) { 17 | tip( 18 | 'It is recommended to externalize dependencies in the server build for ' + 19 | 'better build performance.' 20 | ) 21 | } 22 | } 23 | 24 | export const onEmit = (compiler, name, hook) => { 25 | if (compiler.hooks) { 26 | // Webpack >= 4.0.0 27 | compiler.hooks.emit.tapAsync(name, hook) 28 | } else { 29 | // Webpack < 4.0.0 30 | compiler.plugin('emit', hook) 31 | } 32 | } 33 | 34 | export { isJS, isCSS } from '../util' 35 | -------------------------------------------------------------------------------- /day-3/src/core/instance/render-helpers/check-keycodes.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import config from 'core/config' 4 | import { hyphenate } from 'shared/util' 5 | 6 | function isKeyNotMatch (expect: T | Array, actual: T): boolean { 7 | if (Array.isArray(expect)) { 8 | return expect.indexOf(actual) === -1 9 | } else { 10 | return expect !== actual 11 | } 12 | } 13 | 14 | /** 15 | * Runtime helper for checking keyCodes from config. 16 | * exposed as Vue.prototype._k 17 | * passing in eventKeyName as last argument separately for backwards compat 18 | */ 19 | export function checkKeyCodes ( 20 | eventKeyCode: number, 21 | key: string, 22 | builtInKeyCode?: number | Array, 23 | eventKeyName?: string, 24 | builtInKeyName?: string | Array 25 | ): ?boolean { 26 | const mappedKeyCode = config.keyCodes[key] || builtInKeyCode 27 | if (builtInKeyName && eventKeyName && !config.keyCodes[key]) { 28 | return isKeyNotMatch(builtInKeyName, eventKeyName) 29 | } else if (mappedKeyCode) { 30 | return isKeyNotMatch(mappedKeyCode, eventKeyCode) 31 | } else if (eventKeyName) { 32 | return hyphenate(eventKeyName) !== key 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /day-3/src/core/observer/array.js: -------------------------------------------------------------------------------- 1 | /* 2 | * not type checking this file because flow doesn't play well with 3 | * dynamically accessing methods on Array prototype 4 | */ 5 | 6 | import { def } from '../util/index' 7 | 8 | const arrayProto = Array.prototype 9 | export const arrayMethods = Object.create(arrayProto) 10 | 11 | const methodsToPatch = [ 12 | 'push', 13 | 'pop', 14 | 'shift', 15 | 'unshift', 16 | 'splice', 17 | 'sort', 18 | 'reverse' 19 | ] 20 | 21 | /** 22 | * Intercept mutating methods and emit events 23 | */ 24 | methodsToPatch.forEach(function (method) { 25 | // cache original method 26 | const original = arrayProto[method] 27 | def(arrayMethods, method, function mutator (...args) { 28 | const result = original.apply(this, args) 29 | const ob = this.__ob__ 30 | let inserted 31 | switch (method) { 32 | case 'push': 33 | case 'unshift': 34 | inserted = args 35 | break 36 | case 'splice': 37 | inserted = args.slice(2) 38 | break 39 | } 40 | if (inserted) ob.observeArray(inserted) 41 | // notify change 42 | ob.dep.notify() 43 | return result 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/compiler/modules/props.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { cached, camelize } from 'shared/util' 4 | 5 | const normalize = cached(camelize) 6 | 7 | function normalizeKeyName (str: string): string { 8 | if (str.match(/^v\-/)) { 9 | return str.replace(/(v-[a-z\-]+\:)([a-z\-]+)$/i, ($, directive, prop) => { 10 | return directive + normalize(prop) 11 | }) 12 | } 13 | return normalize(str) 14 | } 15 | 16 | function transformNode (el: ASTElement) { 17 | if (Array.isArray(el.attrsList)) { 18 | el.attrsList.forEach(attr => { 19 | if (attr.name && attr.name.match(/\-/)) { 20 | const realName = normalizeKeyName(attr.name) 21 | if (el.attrsMap) { 22 | el.attrsMap[realName] = el.attrsMap[attr.name] 23 | delete el.attrsMap[attr.name] 24 | } 25 | if (el.rawAttrsMap && el.rawAttrsMap[attr.name]) { 26 | el.rawAttrsMap[realName] = el.rawAttrsMap[attr.name] 27 | // $flow-disable-line 28 | delete el.rawAttrsMap[attr.name] 29 | } 30 | attr.name = realName 31 | } 32 | }) 33 | } 34 | } 35 | export default { 36 | transformNode 37 | } 38 | -------------------------------------------------------------------------------- /day-3/src/server/template-renderer/parse-template.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | const compile = require('lodash.template') 4 | const compileOptions = { 5 | escape: /{{([^{][\s\S]+?[^}])}}/g, 6 | interpolate: /{{{([\s\S]+?)}}}/g 7 | } 8 | 9 | export type ParsedTemplate = { 10 | head: (data: any) => string; 11 | neck: (data: any) => string; 12 | tail: (data: any) => string; 13 | }; 14 | 15 | export function parseTemplate ( 16 | template: string, 17 | contentPlaceholder?: string = '' 18 | ): ParsedTemplate { 19 | if (typeof template === 'object') { 20 | return template 21 | } 22 | 23 | let i = template.indexOf('') 24 | const j = template.indexOf(contentPlaceholder) 25 | 26 | if (j < 0) { 27 | throw new Error(`Content placeholder not found in template.`) 28 | } 29 | 30 | if (i < 0) { 31 | i = template.indexOf('') 32 | if (i < 0) { 33 | i = j 34 | } 35 | } 36 | 37 | return { 38 | head: compile(template.slice(0, i), compileOptions), 39 | neck: compile(template.slice(i, j), compileOptions), 40 | tail: compile(template.slice(j + contentPlaceholder.length), compileOptions) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /day-2/src/App.vue: -------------------------------------------------------------------------------- 1 | 7 | -------------------------------------------------------------------------------- /day-3/vue-auth 2/src/router.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | import Home from './views/Home.vue' 4 | 5 | Vue.use(Router) 6 | export const authRoutes = [ // 权限 7 | { 8 | path: '/cart', 9 | name: 'cart', 10 | component: () => import('@/views/Cart'), 11 | children: [ 12 | { 13 | path: 'cart-list', 14 | name: 'cart-list', 15 | component: () => import('@/views/CartList'), 16 | children: [ 17 | { 18 | path: 'lottery', 19 | name: 'lottery', 20 | component: () => import('@/views/Lottery'), 21 | }, 22 | { 23 | path: 'product', 24 | name: 'product', 25 | component: () => import('@/views/Product'), 26 | }, 27 | ], 28 | }, 29 | ], 30 | }, 31 | ]; 32 | export default new Router({ 33 | mode: 'history', 34 | base: process.env.BASE_URL, 35 | routes: [ 36 | { 37 | path: '/', 38 | name: 'home', 39 | component: Home 40 | }, 41 | { 42 | path:'*', 43 | component:{ 44 | render:h=>h('h1',{},'Not Found') 45 | } 46 | } 47 | ] 48 | }) 49 | -------------------------------------------------------------------------------- /day-3/src/core/vdom/helpers/merge-hook.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import VNode from '../vnode' 4 | import { createFnInvoker } from './update-listeners' 5 | import { remove, isDef, isUndef, isTrue } from 'shared/util' 6 | 7 | export function mergeVNodeHook (def: Object, hookKey: string, hook: Function) { 8 | if (def instanceof VNode) { 9 | def = def.data.hook || (def.data.hook = {}) 10 | } 11 | let invoker 12 | const oldHook = def[hookKey] 13 | 14 | function wrappedHook () { 15 | hook.apply(this, arguments) 16 | // important: remove merged hook to ensure it's called only once 17 | // and prevent memory leak 18 | remove(invoker.fns, wrappedHook) 19 | } 20 | 21 | if (isUndef(oldHook)) { 22 | // no existing hook 23 | invoker = createFnInvoker([wrappedHook]) 24 | } else { 25 | /* istanbul ignore if */ 26 | if (isDef(oldHook.fns) && isTrue(oldHook.merged)) { 27 | // already a merged invoker 28 | invoker = oldHook 29 | invoker.fns.push(wrappedHook) 30 | } else { 31 | // existing plain hook 32 | invoker = createFnInvoker([oldHook, wrappedHook]) 33 | } 34 | } 35 | 36 | invoker.merged = true 37 | def[hookKey] = invoker 38 | } 39 | -------------------------------------------------------------------------------- /day-1/vue-jwt/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-jwt", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "axios": "^0.19.0", 12 | "core-js": "^2.6.5", 13 | "element-ui": "^2.11.1", 14 | "vue": "^2.6.10", 15 | "vue-router": "^3.0.3", 16 | "vuex": "^3.0.1" 17 | }, 18 | "devDependencies": { 19 | "@vue/cli-plugin-babel": "^3.10.0", 20 | "@vue/cli-plugin-eslint": "^3.10.0", 21 | "@vue/cli-service": "^3.10.0", 22 | "@vue/eslint-config-airbnb": "^4.0.0", 23 | "babel-eslint": "^10.0.1", 24 | "body-parser": "^1.19.0", 25 | "eslint": "^5.16.0", 26 | "eslint-plugin-vue": "^5.0.0", 27 | "express": "^4.17.1", 28 | "jsonwebtoken": "^8.5.1", 29 | "less": "^3.0.4", 30 | "less-loader": "^4.1.0", 31 | "lint-staged": "^8.1.5", 32 | "vue-template-compiler": "^2.6.10" 33 | }, 34 | "gitHooks": { 35 | "pre-commit": "lint-staged" 36 | }, 37 | "lint-staged": { 38 | "*.{js,vue}": [ 39 | "vue-cli-service lint", 40 | "git add" 41 | ] 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /day-3/src/core/global-api/assets.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { ASSET_TYPES } from 'shared/constants' 4 | import { isPlainObject, validateComponentName } from '../util/index' 5 | 6 | export function initAssetRegisters (Vue: GlobalAPI) { 7 | /** 8 | * Create asset registration methods. 9 | */ 10 | ASSET_TYPES.forEach(type => { 11 | Vue[type] = function ( 12 | id: string, 13 | definition: Function | Object 14 | ): Function | Object | void { 15 | if (!definition) { 16 | return this.options[type + 's'][id] 17 | } else { 18 | /* istanbul ignore if */ 19 | if (process.env.NODE_ENV !== 'production' && type === 'component') { 20 | validateComponentName(id) 21 | } 22 | if (type === 'component' && isPlainObject(definition)) { 23 | definition.name = definition.name || id 24 | definition = this.options._base.extend(definition) 25 | } 26 | if (type === 'directive' && typeof definition === 'function') { 27 | definition = { bind: definition, update: definition } 28 | } 29 | this.options[type + 's'][id] = definition 30 | return definition 31 | } 32 | } 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /yarn-error.log: -------------------------------------------------------------------------------- 1 | Arguments: 2 | /usr/local/bin/node /usr/local/bin/yarn add uglifyjs-webpacl-plugin@1.0.0-beta.1 3 | 4 | PATH: 5 | /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin 6 | 7 | Yarn version: 8 | 1.17.3 9 | 10 | Node version: 11 | 11.14.0 12 | 13 | Platform: 14 | darwin x64 15 | 16 | Trace: 17 | Error: https://registry.npm.taobao.org/uglifyjs-webpacl-plugin: Not found 18 | at Request.params.callback [as _callback] (/usr/local/lib/node_modules/yarn/lib/cli.js:66830:18) 19 | at Request.self.callback (/usr/local/lib/node_modules/yarn/lib/cli.js:140464:22) 20 | at Request.emit (events.js:193:13) 21 | at Request. (/usr/local/lib/node_modules/yarn/lib/cli.js:141436:10) 22 | at Request.emit (events.js:193:13) 23 | at IncomingMessage. (/usr/local/lib/node_modules/yarn/lib/cli.js:141358:12) 24 | at Object.onceWrapper (events.js:281:20) 25 | at IncomingMessage.emit (events.js:198:15) 26 | at endReadableNT (_stream_readable.js:1139:12) 27 | at processTicksAndRejections (internal/process/task_queues.js:81:17) 28 | 29 | npm manifest: 30 | No manifest 31 | 32 | yarn manifest: 33 | No manifest 34 | 35 | Lockfile: 36 | No lockfile 37 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/runtime/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import Vue from 'core/index' 4 | import { patch } from 'weex/runtime/patch' 5 | import { mountComponent } from 'core/instance/lifecycle' 6 | import platformDirectives from 'weex/runtime/directives/index' 7 | import platformComponents from 'weex/runtime/components/index' 8 | 9 | import { 10 | query, 11 | mustUseProp, 12 | isReservedTag, 13 | isRuntimeComponent, 14 | isUnknownElement 15 | } from 'weex/util/element' 16 | 17 | // install platform specific utils 18 | Vue.config.mustUseProp = mustUseProp 19 | Vue.config.isReservedTag = isReservedTag 20 | Vue.config.isRuntimeComponent = isRuntimeComponent 21 | Vue.config.isUnknownElement = isUnknownElement 22 | 23 | // install platform runtime directives and components 24 | Vue.options.directives = platformDirectives 25 | Vue.options.components = platformComponents 26 | 27 | // install platform patch function 28 | Vue.prototype.__patch__ = patch 29 | 30 | // wrap mount 31 | Vue.prototype.$mount = function ( 32 | el?: any, 33 | hydrating?: boolean 34 | ): Component { 35 | return mountComponent( 36 | this, 37 | el && query(el, this.$document), 38 | hydrating 39 | ) 40 | } 41 | 42 | export default Vue 43 | -------------------------------------------------------------------------------- /day-1/vue-jwt/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import ElementUI from 'element-ui'; 3 | import App from './App.vue'; 4 | import router from './router'; 5 | import store from './store'; 6 | import 'element-ui/lib/theme-chalk/index.css'; 7 | 8 | // home 显示首页 9 | // login 登录页面 10 | // profile 个人中心页面 11 | const whiteList = ['/']; 12 | router.beforeEach(async (to, from, next) => { // 路由的渲染流程 钩子的执行顺序 13 | // 要校验一下 当前用户登录没登录 14 | if (whiteList.includes(to.path)) { 15 | return next(); 16 | } 17 | const flag = await store.dispatch('validate'); 18 | if (flag) { 19 | if (to.path === '/login') { 20 | next('/'); 21 | } else { 22 | next(); // 登录过而且不是login 那就ok 跳转吧 23 | } 24 | } else { 25 | // 没登录过 ,如果这条路由 还需要登录那么就跳转到登录页面 26 | // 看vue文档 27 | const flag = to.matched.some(item => item.meta.needLogin); 28 | if (flag) { 29 | next('/login'); 30 | } else { 31 | next(); 32 | } 33 | } 34 | next(); 35 | }); 36 | 37 | // vuex 38 | Vue.use(ElementUI); 39 | Vue.config.productionTip = false; 40 | 41 | new Vue({ 42 | router, 43 | store, 44 | render: h => h(App), 45 | }).$mount('#app'); 46 | 47 | 48 | // 咱们课程 现在报名有优惠 下次 49 | // 8月17日 周二周四晚上 8-10 周六全天 50 | 51 | // 给腾讯课堂个好评 52 | // 感谢大家的坚持 53 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/runtime/modules/attrs.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { extend } from 'shared/util' 4 | 5 | function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) { 6 | if (!oldVnode.data.attrs && !vnode.data.attrs) { 7 | return 8 | } 9 | let key, cur, old 10 | const elm = vnode.elm 11 | const oldAttrs = oldVnode.data.attrs || {} 12 | let attrs = vnode.data.attrs || {} 13 | // clone observed objects, as the user probably wants to mutate it 14 | if (attrs.__ob__) { 15 | attrs = vnode.data.attrs = extend({}, attrs) 16 | } 17 | 18 | const supportBatchUpdate = typeof elm.setAttrs === 'function' 19 | const batchedAttrs = {} 20 | for (key in attrs) { 21 | cur = attrs[key] 22 | old = oldAttrs[key] 23 | if (old !== cur) { 24 | supportBatchUpdate 25 | ? (batchedAttrs[key] = cur) 26 | : elm.setAttr(key, cur) 27 | } 28 | } 29 | for (key in oldAttrs) { 30 | if (attrs[key] == null) { 31 | supportBatchUpdate 32 | ? (batchedAttrs[key] = undefined) 33 | : elm.setAttr(key) 34 | } 35 | } 36 | if (supportBatchUpdate) { 37 | elm.setAttrs(batchedAttrs) 38 | } 39 | } 40 | 41 | export default { 42 | create: updateAttrs, 43 | update: updateAttrs 44 | } 45 | -------------------------------------------------------------------------------- /day-3/src/core/vdom/modules/ref.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { remove, isDef } from 'shared/util' 4 | 5 | export default { 6 | create (_: any, vnode: VNodeWithData) { 7 | registerRef(vnode) 8 | }, 9 | update (oldVnode: VNodeWithData, vnode: VNodeWithData) { 10 | if (oldVnode.data.ref !== vnode.data.ref) { 11 | registerRef(oldVnode, true) 12 | registerRef(vnode) 13 | } 14 | }, 15 | destroy (vnode: VNodeWithData) { 16 | registerRef(vnode, true) 17 | } 18 | } 19 | 20 | export function registerRef (vnode: VNodeWithData, isRemoval: ?boolean) { 21 | const key = vnode.data.ref 22 | if (!isDef(key)) return 23 | 24 | const vm = vnode.context 25 | const ref = vnode.componentInstance || vnode.elm 26 | const refs = vm.$refs 27 | if (isRemoval) { 28 | if (Array.isArray(refs[key])) { 29 | remove(refs[key], ref) 30 | } else if (refs[key] === ref) { 31 | refs[key] = undefined 32 | } 33 | } else { 34 | if (vnode.data.refInFor) { 35 | if (!Array.isArray(refs[key])) { 36 | refs[key] = [ref] 37 | } else if (refs[key].indexOf(ref) < 0) { 38 | // $flow-disable-line 39 | refs[key].push(ref) 40 | } 41 | } else { 42 | refs[key] = ref 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/runtime/recycle-list/render-component-template.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { warn } from 'core/util/debug' 4 | import { handleError } from 'core/util/error' 5 | import { RECYCLE_LIST_MARKER } from 'weex/util/index' 6 | import { createComponentInstanceForVnode } from 'core/vdom/create-component' 7 | import { resolveVirtualComponent } from './virtual-component' 8 | 9 | export function isRecyclableComponent (vnode: VNodeWithData): boolean { 10 | return vnode.data.attrs 11 | ? (RECYCLE_LIST_MARKER in vnode.data.attrs) 12 | : false 13 | } 14 | 15 | export function renderRecyclableComponentTemplate (vnode: MountedComponentVNode): VNode { 16 | // $flow-disable-line 17 | delete vnode.data.attrs[RECYCLE_LIST_MARKER] 18 | resolveVirtualComponent(vnode) 19 | const vm = createComponentInstanceForVnode(vnode) 20 | const render = (vm.$options: any)['@render'] 21 | if (render) { 22 | try { 23 | return render.call(vm) 24 | } catch (err) { 25 | handleError(err, vm, `@render`) 26 | } 27 | } else { 28 | warn( 29 | `@render function not defined on component used in . ` + 30 | `Make sure to declare \`recyclable="true"\` on the component's template.`, 31 | vm 32 | ) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/server/modules/style.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { escape, noUnitNumericStyleProps } from '../util' 4 | import { hyphenate } from 'shared/util' 5 | import { getStyle } from 'web/util/style' 6 | 7 | export function genStyle (style: Object): string { 8 | let styleText = '' 9 | for (const key in style) { 10 | const value = style[key] 11 | const hyphenatedKey = hyphenate(key) 12 | if (Array.isArray(value)) { 13 | for (let i = 0, len = value.length; i < len; i++) { 14 | styleText += normalizeValue(hyphenatedKey, value[i]) 15 | } 16 | } else { 17 | styleText += normalizeValue(hyphenatedKey, value) 18 | } 19 | } 20 | return styleText 21 | } 22 | 23 | function normalizeValue(key: string, value: any): string { 24 | if ( 25 | typeof value === 'string' || 26 | (typeof value === 'number' && noUnitNumericStyleProps[key]) || 27 | value === 0 28 | ) { 29 | return `${key}:${value};` 30 | } else { 31 | // invalid values 32 | return `` 33 | } 34 | } 35 | 36 | export default function renderStyle (vnode: VNodeWithData): ?string { 37 | const styleText = genStyle(getStyle(vnode, false)) 38 | if (styleText !== '') { 39 | return ` style=${JSON.stringify(escape(styleText))}` 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /day-1/vue-component/history2/App.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | -------------------------------------------------------------------------------- /day-1/vue-component/history1/components/Parent.vue: -------------------------------------------------------------------------------- 1 | 21 | 22 | -------------------------------------------------------------------------------- /day-3/src/core/instance/render-helpers/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { toNumber, toString, looseEqual, looseIndexOf } from 'shared/util' 4 | import { createTextVNode, createEmptyVNode } from 'core/vdom/vnode' 5 | import { renderList } from './render-list' 6 | import { renderSlot } from './render-slot' 7 | import { resolveFilter } from './resolve-filter' 8 | import { checkKeyCodes } from './check-keycodes' 9 | import { bindObjectProps } from './bind-object-props' 10 | import { renderStatic, markOnce } from './render-static' 11 | import { bindObjectListeners } from './bind-object-listeners' 12 | import { resolveScopedSlots } from './resolve-scoped-slots' 13 | import { bindDynamicKeys, prependModifier } from './bind-dynamic-keys' 14 | 15 | export function installRenderHelpers (target: any) { 16 | target._o = markOnce 17 | target._n = toNumber 18 | target._s = toString 19 | target._l = renderList 20 | target._t = renderSlot 21 | target._q = looseEqual 22 | target._i = looseIndexOf 23 | target._m = renderStatic 24 | target._f = resolveFilter 25 | target._k = checkKeyCodes 26 | target._b = bindObjectProps 27 | target._v = createTextVNode 28 | target._e = createEmptyVNode 29 | target._u = resolveScopedSlots 30 | target._g = bindObjectListeners 31 | target._d = bindDynamicKeys 32 | target._p = prependModifier 33 | } 34 | -------------------------------------------------------------------------------- /day-2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zf-cascader", 3 | "version": "1.0.1", 4 | "private": false, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint", 9 | "dist": "vue-cli-service build --target lib --name Cascader ./src/components/Cascader.vue", 10 | "test:unit": "vue-cli-service test:unit" 11 | }, 12 | "dependencies": { 13 | "core-js": "^2.6.5", 14 | "lodash": "^4.17.15", 15 | "vue": "^2.6.10" 16 | }, 17 | "devDependencies": { 18 | "@vue/cli-plugin-babel": "^3.10.0", 19 | "@vue/cli-plugin-eslint": "^3.10.0", 20 | "@vue/cli-plugin-unit-jest": "^3.10.0", 21 | "@vue/cli-service": "^3.10.0", 22 | "@vue/eslint-config-airbnb": "^4.0.0", 23 | "@vue/test-utils": "1.0.0-beta.29", 24 | "babel-core": "7.0.0-bridge.0", 25 | "babel-eslint": "^10.0.1", 26 | "babel-jest": "^23.6.0", 27 | "eslint": "^5.16.0", 28 | "eslint-plugin-vue": "^5.0.0", 29 | "lint-staged": "^8.1.5", 30 | "stylus": "^0.54.5", 31 | "stylus-loader": "^3.0.2", 32 | "vue-template-compiler": "^2.6.10" 33 | }, 34 | "gitHooks": { 35 | "pre-commit": "lint-staged" 36 | }, 37 | "lint-staged": { 38 | "*.{js,vue}": [ 39 | "vue-cli-service lint", 40 | "git add" 41 | ] 42 | }, 43 | "main":"./dist/Cascader.umd.min.js" 44 | } 45 | -------------------------------------------------------------------------------- /day-3/src/core/instance/render-helpers/bind-dynamic-keys.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | // helper to process dynamic keys for dynamic arguments in v-bind and v-on. 4 | // For example, the following template: 5 | // 6 | //
7 | // 8 | // compiles to the following: 9 | // 10 | // _c('div', { attrs: bindDynamicKeys({ "id": "app" }, [key, value]) }) 11 | 12 | import { warn } from 'core/util/debug' 13 | 14 | export function bindDynamicKeys (baseObj: Object, values: Array): Object { 15 | for (let i = 0; i < values.length; i += 2) { 16 | const key = values[i] 17 | if (typeof key === 'string' && key) { 18 | baseObj[values[i]] = values[i + 1] 19 | } else if (process.env.NODE_ENV !== 'production' && key !== '' && key !== null) { 20 | // null is a special value for explicitly removing a binding 21 | warn( 22 | `Invalid value for dynamic directive argument (expected string or null): ${key}`, 23 | this 24 | ) 25 | } 26 | } 27 | return baseObj 28 | } 29 | 30 | // helper to dynamically append modifier runtime markers to event names. 31 | // ensure only append when value is already string, otherwise it will be cast 32 | // to string and cause the type check to miss. 33 | export function prependModifier (value: any, symbol: string): any { 34 | return typeof value === 'string' ? symbol + value : value 35 | } 36 | -------------------------------------------------------------------------------- /day-3/src/core/util/lang.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | /** 4 | * unicode letters used for parsing html tags, component names and property paths. 5 | * using https://www.w3.org/TR/html53/semantics-scripting.html#potentialcustomelementname 6 | * skipping \u10000-\uEFFFF due to it freezing up PhantomJS 7 | */ 8 | export const unicodeRegExp = /a-zA-Z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD/ 9 | 10 | /** 11 | * Check if a string starts with $ or _ 12 | */ 13 | export function isReserved (str: string): boolean { 14 | const c = (str + '').charCodeAt(0) 15 | return c === 0x24 || c === 0x5F 16 | } 17 | 18 | /** 19 | * Define a property. 20 | */ 21 | export function def (obj: Object, key: string, val: any, enumerable?: boolean) { 22 | Object.defineProperty(obj, key, { 23 | value: val, 24 | enumerable: !!enumerable, 25 | writable: true, 26 | configurable: true 27 | }) 28 | } 29 | 30 | /** 31 | * Parse simple path. 32 | */ 33 | const bailRE = new RegExp(`[^${unicodeRegExp.source}.$_\\d]`) 34 | export function parsePath (path: string): any { 35 | if (bailRE.test(path)) { 36 | return 37 | } 38 | const segments = path.split('.') 39 | return function (obj) { 40 | for (let i = 0; i < segments.length; i++) { 41 | if (!obj) return 42 | obj = obj[segments[i]] 43 | } 44 | return obj 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/compiler/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { genStaticKeys } from 'shared/util' 4 | import { createCompiler } from 'compiler/index' 5 | 6 | import modules from './modules/index' 7 | import directives from './directives/index' 8 | 9 | import { 10 | isUnaryTag, 11 | mustUseProp, 12 | isReservedTag, 13 | canBeLeftOpenTag, 14 | getTagNamespace 15 | } from '../util/element' 16 | 17 | export const baseOptions: WeexCompilerOptions = { 18 | modules, 19 | directives, 20 | isUnaryTag, 21 | mustUseProp, 22 | canBeLeftOpenTag, 23 | isReservedTag, 24 | getTagNamespace, 25 | preserveWhitespace: false, 26 | recyclable: false, 27 | staticKeys: genStaticKeys(modules) 28 | } 29 | 30 | const compiler = createCompiler(baseOptions) 31 | 32 | export function compile ( 33 | template: string, 34 | options?: WeexCompilerOptions 35 | ): WeexCompiledResult { 36 | let generateAltRender = false 37 | if (options && options.recyclable === true) { 38 | generateAltRender = true 39 | options.recyclable = false 40 | } 41 | const result = compiler.compile(template, options) 42 | 43 | // generate @render function for 44 | if (options && generateAltRender) { 45 | options.recyclable = true 46 | // disable static optimizations 47 | options.optimize = false 48 | const { render } = compiler.compile(template, options) 49 | result['@render'] = render 50 | } 51 | return result 52 | } 53 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/runtime/modules/events.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { updateListeners } from 'core/vdom/helpers/update-listeners' 4 | 5 | let target: any 6 | 7 | function createOnceHandler (event, handler, capture) { 8 | const _target = target // save current target element in closure 9 | return function onceHandler () { 10 | const res = handler.apply(null, arguments) 11 | if (res !== null) { 12 | remove(event, onceHandler, capture, _target) 13 | } 14 | } 15 | } 16 | 17 | function add ( 18 | event: string, 19 | handler: Function, 20 | capture: boolean, 21 | passive?: boolean, 22 | params?: Array 23 | ) { 24 | if (capture) { 25 | console.log('Weex do not support event in bubble phase.') 26 | return 27 | } 28 | target.addEvent(event, handler, params) 29 | } 30 | 31 | function remove ( 32 | event: string, 33 | handler: any, 34 | capture: any, 35 | _target?: any 36 | ) { 37 | (_target || target).removeEvent(event) 38 | } 39 | 40 | function updateDOMListeners (oldVnode: VNodeWithData, vnode: VNodeWithData) { 41 | if (!oldVnode.data.on && !vnode.data.on) { 42 | return 43 | } 44 | const on = vnode.data.on || {} 45 | const oldOn = oldVnode.data.on || {} 46 | target = vnode.elm 47 | updateListeners(on, oldOn, add, remove, createOnceHandler, vnode.context) 48 | target = undefined 49 | } 50 | 51 | export default { 52 | create: updateDOMListeners, 53 | update: updateDOMListeners 54 | } 55 | -------------------------------------------------------------------------------- /day-3/src/platforms/weex/util/index.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | declare var document: WeexDocument; 3 | 4 | import { warn } from 'core/util/index' 5 | 6 | export const RECYCLE_LIST_MARKER = '@inRecycleList' 7 | 8 | // Register the component hook to weex native render engine. 9 | // The hook will be triggered by native, not javascript. 10 | export function registerComponentHook ( 11 | componentId: string, 12 | type: string, // hook type, could be "lifecycle" or "instance" 13 | hook: string, // hook name 14 | fn: Function 15 | ) { 16 | if (!document || !document.taskCenter) { 17 | warn(`Can't find available "document" or "taskCenter".`) 18 | return 19 | } 20 | if (typeof document.taskCenter.registerHook === 'function') { 21 | return document.taskCenter.registerHook(componentId, type, hook, fn) 22 | } 23 | warn(`Failed to register component hook "${type}@${hook}#${componentId}".`) 24 | } 25 | 26 | // Updates the state of the component to weex native render engine. 27 | export function updateComponentData ( 28 | componentId: string, 29 | newData: Object | void, 30 | callback?: Function 31 | ) { 32 | if (!document || !document.taskCenter) { 33 | warn(`Can't find available "document" or "taskCenter".`) 34 | return 35 | } 36 | if (typeof document.taskCenter.updateData === 'function') { 37 | return document.taskCenter.updateData(componentId, newData, callback) 38 | } 39 | warn(`Failed to update component data (${componentId}).`) 40 | } 41 | -------------------------------------------------------------------------------- /day-3/src/server/bundle-renderer/source-map-support.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | const SourceMapConsumer = require('source-map').SourceMapConsumer 4 | 5 | const filenameRE = /\(([^)]+\.js):(\d+):(\d+)\)$/ 6 | 7 | export function createSourceMapConsumers (rawMaps: Object) { 8 | const maps = {} 9 | Object.keys(rawMaps).forEach(file => { 10 | maps[file] = new SourceMapConsumer(rawMaps[file]) 11 | }) 12 | return maps 13 | } 14 | 15 | export function rewriteErrorTrace (e: any, mapConsumers: { 16 | [key: string]: SourceMapConsumer 17 | }) { 18 | if (e && typeof e.stack === 'string') { 19 | e.stack = e.stack.split('\n').map(line => { 20 | return rewriteTraceLine(line, mapConsumers) 21 | }).join('\n') 22 | } 23 | } 24 | 25 | function rewriteTraceLine (trace: string, mapConsumers: { 26 | [key: string]: SourceMapConsumer 27 | }) { 28 | const m = trace.match(filenameRE) 29 | const map = m && mapConsumers[m[1]] 30 | if (m != null && map) { 31 | const originalPosition = map.originalPositionFor({ 32 | line: Number(m[2]), 33 | column: Number(m[3]) 34 | }) 35 | if (originalPosition.source != null) { 36 | const { source, line, column } = originalPosition 37 | const mappedPosition = `(${source.replace(/^webpack:\/\/\//, '')}:${String(line)}:${String(column)})` 38 | return trace.replace(filenameRE, mappedPosition) 39 | } else { 40 | return trace 41 | } 42 | } else { 43 | return trace 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /day-3/src/core/instance/render-helpers/render-list.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { isObject, isDef, hasSymbol } from 'core/util/index' 4 | 5 | /** 6 | * Runtime helper for rendering v-for lists. 7 | */ 8 | export function renderList ( 9 | val: any, 10 | render: ( 11 | val: any, 12 | keyOrIndex: string | number, 13 | index?: number 14 | ) => VNode 15 | ): ?Array { 16 | let ret: ?Array, i, l, keys, key 17 | if (Array.isArray(val) || typeof val === 'string') { 18 | ret = new Array(val.length) 19 | for (i = 0, l = val.length; i < l; i++) { 20 | ret[i] = render(val[i], i) 21 | } 22 | } else if (typeof val === 'number') { 23 | ret = new Array(val) 24 | for (i = 0; i < val; i++) { 25 | ret[i] = render(i + 1, i) 26 | } 27 | } else if (isObject(val)) { 28 | if (hasSymbol && val[Symbol.iterator]) { 29 | ret = [] 30 | const iterator: Iterator = val[Symbol.iterator]() 31 | let result = iterator.next() 32 | while (!result.done) { 33 | ret.push(render(result.value, ret.length)) 34 | result = iterator.next() 35 | } 36 | } else { 37 | keys = Object.keys(val) 38 | ret = new Array(keys.length) 39 | for (i = 0, l = keys.length; i < l; i++) { 40 | key = keys[i] 41 | ret[i] = render(val[key], key, i) 42 | } 43 | } 44 | } 45 | if (!isDef(ret)) { 46 | ret = [] 47 | } 48 | (ret: any)._isVList = true 49 | return ret 50 | } 51 | -------------------------------------------------------------------------------- /day-3/src/platforms/web/server/directives/model.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { looseEqual, looseIndexOf } from 'shared/util' 4 | 5 | // this is only applied for