开始学习插件

new_branch1
roger 2 years ago
parent 29403d0f84
commit e354141f65
  1. 19
      20_脚手架/vue_code/04.src_插件/App.vue
  2. BIN
      20_脚手架/vue_code/04.src_插件/assets/logo.png
  3. 27
      20_脚手架/vue_code/04.src_插件/components/School.vue
  4. 21
      20_脚手架/vue_code/04.src_插件/components/Student.vue
  5. 20
      20_脚手架/vue_code/04.src_插件/main.js
  6. 34
      20_脚手架/vue_code/04.src_插件/plugins.js
  7. 1
      20_脚手架/vue_code/src/App.vue
  8. 17
      20_脚手架/vue_code/src/components/School.vue
  9. 13
      20_脚手架/vue_code/src/components/Student.vue
  10. 14
      20_脚手架/vue_code/src/main.js
  11. 17
      20_脚手架/vue_code/src/mixin.js
  12. 34
      20_脚手架/vue_code/src/plugins.js

@ -0,0 +1,19 @@
<template>
<div>
<School/>
<Student/>
</div>
</template>
<script>
import School from "./components/School.vue";
import Student from "./components/Student.vue";
export default {
name: "App",
components: {
School,
Student
}
}
</script>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

@ -0,0 +1,27 @@
<template>
<div>
<h2>学校名称{{ name | mySlice}}</h2>
<h2>学校地址{{ address }}</h2>
<button @click="test">点击触发hello方法</button>
</div>
</template>
<script>
export default {
name: "School",
data() {
return {
name: "修仙学院修仙学院修仙学院",
address: "长白山",
msg: "欢迎学校" // vc
}
},
methods: {
test() {
this.hello()
}
}
}
</script>

@ -0,0 +1,21 @@
<template>
<div>
<h2>学生名称{{ name }}</h2>
<h2>学生年龄{{ age }}</h2>
<input type="text" v-fbind:value="name">
</div>
</template>
<script>
export default {
name: "Student",
data() {
return {
name: "小强",
age: 18,
msg: "欢迎学生"
}
}
}
</script>

@ -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')

@ -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')}
}
}

@ -9,7 +9,6 @@
import School from "./components/School.vue";
import Student from "./components/Student.vue";
export default {
name: "App",
components: {

@ -1,28 +1,27 @@
<template>
<div>
<h2 @click="showName">学校名称{{ name }}</h2>
<h2>学校名称{{ name | mySlice}}</h2>
<h2>学校地址{{ address }}</h2>
<button @click="test">点击触发hello方法</button>
</div>
</template>
<script>
//
// import {mixin_method1, mixin_method2} from "@/mixin";
export default {
name: "School",
data() {
return {
name: "修仙学院",
name: "修仙学院修仙学院修仙学院",
address: "长白山",
msg: "欢迎学校" // vc
}
},
mounted() {
console.log(this.msg) // mixinvc
},
//
// mixins: [mixin_method1, mixin_method2]
methods: {
test() {
this.hello()
}
}
}
</script>

@ -1,14 +1,12 @@
<template>
<div>
<h2 @click="showName">学生名称{{ name }}</h2>
<h2>学生名称{{ name }}</h2>
<h2>学生年龄{{ age }}</h2>
<input type="text" v-fbind:value="name">
</div>
</template>
<script>
//
// import {mixin_method1, mixin_method2} from "../mixin";
export default {
name: "Student",
data() {
@ -17,12 +15,7 @@ export default {
age: 18,
msg: "欢迎学生"
}
},
mounted() {
console.log(this.msg)
},
//
// mixins: [mixin_method1, mixin_method2]
}
}
</script>

@ -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

@ -1,17 +0,0 @@
export const mixin_method1 = {
methods: {
showName() {
alert(this.name)
}
},
mounted() {
console.log("欢迎")
}
}
export const mixin_method2 = {
data() {
return {
msg: "欢迎"
}
}
}

@ -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')}
}
}
Loading…
Cancel
Save