diff --git a/20_脚手架/vue_code/04.src_插件/App.vue b/20_脚手架/vue_code/04.src_插件/App.vue new file mode 100644 index 0000000..197be06 --- /dev/null +++ b/20_脚手架/vue_code/04.src_插件/App.vue @@ -0,0 +1,19 @@ + + + \ No newline at end of file diff --git a/20_脚手架/vue_code/04.src_插件/assets/logo.png b/20_脚手架/vue_code/04.src_插件/assets/logo.png new file mode 100644 index 0000000..f3d2503 Binary files /dev/null and b/20_脚手架/vue_code/04.src_插件/assets/logo.png differ diff --git a/20_脚手架/vue_code/04.src_插件/components/School.vue b/20_脚手架/vue_code/04.src_插件/components/School.vue new file mode 100644 index 0000000..f8487cb --- /dev/null +++ b/20_脚手架/vue_code/04.src_插件/components/School.vue @@ -0,0 +1,27 @@ + + + + diff --git a/20_脚手架/vue_code/04.src_插件/components/Student.vue b/20_脚手架/vue_code/04.src_插件/components/Student.vue new file mode 100644 index 0000000..5c9795f --- /dev/null +++ b/20_脚手架/vue_code/04.src_插件/components/Student.vue @@ -0,0 +1,21 @@ + + + + diff --git a/20_脚手架/vue_code/04.src_插件/main.js b/20_脚手架/vue_code/04.src_插件/main.js new file mode 100644 index 0000000..9b213cd --- /dev/null +++ b/20_脚手架/vue_code/04.src_插件/main.js @@ -0,0 +1,20 @@ +// 引入Vue +import Vue from "vue"; +// 引入App +import App from "./App"; +// 引入插件 +import plugins from "./plugins" + +// 设置Vue +Vue.config.productionTip = false + +// 使用插件 +Vue.use(plugins) + +// 实例化Vue +new Vue({ + components: { + App + }, + render: h => h(App) +}).$mount('#app') diff --git a/20_脚手架/vue_code/04.src_插件/plugins.js b/20_脚手架/vue_code/04.src_插件/plugins.js new file mode 100644 index 0000000..ab8d224 --- /dev/null +++ b/20_脚手架/vue_code/04.src_插件/plugins.js @@ -0,0 +1,34 @@ +export default { + install(Vue) { + // 全局过滤器 + Vue.filter("mySlice", function (value) { + return value.slice(0, 4) + }) + + // 全局指令 + Vue.directive("fbind", { + bind(element, binding) { + element.value = binding.value + }, + inserted(element, binding) { + element.focus() + }, + update(element, binding) { + element.value = binding.value + } + }) + + // 定义混入 + Vue.mixin({ + data() { + return { + x: 100, + y: 200 + } + } + }) + + // 给Vue原型上添加一个方法 + Vue.prototype.hello = ()=> {alert('Hello')} + } +} \ No newline at end of file diff --git a/20_脚手架/vue_code/src/App.vue b/20_脚手架/vue_code/src/App.vue index ba65631..197be06 100644 --- a/20_脚手架/vue_code/src/App.vue +++ b/20_脚手架/vue_code/src/App.vue @@ -9,7 +9,6 @@ import School from "./components/School.vue"; import Student from "./components/Student.vue"; - export default { name: "App", components: { diff --git a/20_脚手架/vue_code/src/components/School.vue b/20_脚手架/vue_code/src/components/School.vue index 028b976..f8487cb 100644 --- a/20_脚手架/vue_code/src/components/School.vue +++ b/20_脚手架/vue_code/src/components/School.vue @@ -1,28 +1,27 @@ diff --git a/20_脚手架/vue_code/src/components/Student.vue b/20_脚手架/vue_code/src/components/Student.vue index f493a7c..5c9795f 100644 --- a/20_脚手架/vue_code/src/components/Student.vue +++ b/20_脚手架/vue_code/src/components/Student.vue @@ -1,14 +1,12 @@ diff --git a/20_脚手架/vue_code/src/main.js b/20_脚手架/vue_code/src/main.js index 2aab4d0..9b213cd 100644 --- a/20_脚手架/vue_code/src/main.js +++ b/20_脚手架/vue_code/src/main.js @@ -1,13 +1,17 @@ +// 引入Vue import Vue from "vue"; +// 引入App import App from "./App"; +// 引入插件 +import plugins from "./plugins" -import {mixin_method1, mixin_method2} from "@/mixin"; - - +// 设置Vue Vue.config.productionTip = false -Vue.mixin(mixin_method1) -Vue.mixin(mixin_method2) +// 使用插件 +Vue.use(plugins) + +// 实例化Vue new Vue({ components: { App diff --git a/20_脚手架/vue_code/src/mixin.js b/20_脚手架/vue_code/src/mixin.js deleted file mode 100644 index c41bd4f..0000000 --- a/20_脚手架/vue_code/src/mixin.js +++ /dev/null @@ -1,17 +0,0 @@ -export const mixin_method1 = { - methods: { - showName() { - alert(this.name) - } - }, - mounted() { - console.log("欢迎") - } -} -export const mixin_method2 = { - data() { - return { - msg: "欢迎" - } - } -} \ No newline at end of file diff --git a/20_脚手架/vue_code/src/plugins.js b/20_脚手架/vue_code/src/plugins.js new file mode 100644 index 0000000..ab8d224 --- /dev/null +++ b/20_脚手架/vue_code/src/plugins.js @@ -0,0 +1,34 @@ +export default { + install(Vue) { + // 全局过滤器 + Vue.filter("mySlice", function (value) { + return value.slice(0, 4) + }) + + // 全局指令 + Vue.directive("fbind", { + bind(element, binding) { + element.value = binding.value + }, + inserted(element, binding) { + element.focus() + }, + update(element, binding) { + element.value = binding.value + } + }) + + // 定义混入 + Vue.mixin({ + data() { + return { + x: 100, + y: 200 + } + } + }) + + // 给Vue原型上添加一个方法 + Vue.prototype.hello = ()=> {alert('Hello')} + } +} \ No newline at end of file