Skip to content

使用

基本使用

模板(插值,指令

img.png

computed和watch

img_1.png

class和style

img_2.png

条件

v-show是display:none v-if 是组件销毁重建

循环

要加唯一的key

事件

子调父方法

img_3.pngimg_4.png

父调子方法

使用ref:this.$refs.one.oneSubmit()

事件修饰符

img_5.png

按键修饰符

img_6.png

表单修饰符

img_7.png

组件

生命周期

img_1.pngimg_2.pngimg_3.png

props

v-on和$emit

自定义事件

高级特性

自定义v-model

img_11.pngimg_12.png

$nextTick

img_13.png

refs

slot

基本使用

img_14.png

具名插槽

img_15.png

动态组件

img_16.png

异步组件

img_17.png

keep-alive

img_18.png

mixin

img_19.pngimg_20.pngimg_21.png

directive全局指令

全局权限

js
const app = createApp(App)
// 实现全局指令
app.directive('auth', (el, binding) => {
  let auths = ['edit', 'delete'];
  let ret = auths.includes(binding.value);
  if(!ret){
    el.style.display = 'none';
  }
});
app.mount('#app')
html
<button v-auth="'edit'">编辑</button>

https

main.js

js
import * as http from '@/5_http.js'
//实现全局属性
app.config.globalProperties.$http = http;

get.js

js
function get(){
  console.log('get request');
}
export {
  get
}

install插件

main.js

js
//实现插件的初始化
import myplugin from './myplugin.js'
app.use(myplugin, { info: '配置信息' })

myplugin.js

js
import * as http from '@/5_http.js'
export default {
  install(app, options){
    console.log(options);
    app.config.globalProperties.$http = http;
    app.directive('auth', (el, binding) => {
      let auths = ['edit', 'delete'];
      let ret = auths.includes(binding.value);
      if(!ret){
        el.style.display = 'none';
      }
    });
  }
}