vue基于vant封装日期组件

  • 在src/main.js中引入组件
import components from './components'
/******----- 自定义组件 -----******/
for (let k in components) {
    Vue.use(components[k]);
}
  • 在src/components/index.js 中导出组件
import VantCalendar from './vantCalendar' //日期组件
let components = {
  VantCalendar
}

export default components;
  • 在src/components目录下新建文件夹 vantCalendar,里面新建两个文件index.js和VantCalendar.vue
  • 在src/components/vantCalendar/index.js中注册组件
import vantCalendar from "./VantCalendar.vue";

const VantCalendar = {
  install(Vue) {
    Vue.component(vantCalendar.name, vantCalendar);
  }
};

export default VantCalendar;
  •  在src/components/vantCalendar/VantCalendar.vue中写组件封装的逻辑,使用v-bind="$attrs"和v-on="$listeners"实现在父组件调用时子组件可以使用原生

你可能感兴趣的:(vant-ui,vue.js,前端,javascript)