반응형
1. vue-js-modal 을 install 받아준다
npm install vue-js-modal --save
https://www.npmjs.com/package/vue-js-modal
vue-js-modal
Modal Component for Vue.js. Latest version: 2.0.1, last published: a year ago. Start using vue-js-modal in your project by running `npm i vue-js-modal`. There are 187 other projects in the npm registry using vue-js-modal.
www.npmjs.com
2. main.js에 vue-js-modal 플러그인을 추가해준다.
import Vue from 'vue';
import App from './App.vue';
import VueJsModal from 'vue-js-modal';
Vue.use(VueJsModal, {
dialog: true,
dynamicDefaults: {
draggable: true,
},
});
Vue.config.productionTip = false;
new Vue({
render: h => h(App),
router,
}).$mount('#app');
3. vue 파일에 이 코드를 넣어준다
<template>
<div id="app">
<button v-on:click="show">show!</button>
<modal name="hello-world" :draggable="true">
<p>hello, world!</p>
<button v-on:click="hide">hide</button>
</modal>
</div>
</template>
<script>
export default {
data() {
return {};
},
mounted() {},
methods: {
show(){
this.$modal.show('hello-world');
},
hide(){
this.$modal.hide('hello-world');
},
};
</script>
<style lang="scss" scoped></style>
4. 완성. CSS는 프로젝트에 맞게 만들어서 쓰면 끝
5. 이건 참고한 코드펜 주소
- vue.js 에서 드래그 되는 모달창 만들려고 검색하다가 찾은건데
- 코드만 있고 vue-js-modal 을 install 받아야 하는게 없어서 검색하다가 찾은 방법을 포스팅 해 본다
- 여기 들어가서 보면 드래그 되는 Modal 창 미리 확인해 볼 수 있음
https://codepen.io/kabanoki/pen/MRXNGy
Vue.js modal draggable
...
codepen.io
반응형
'실무 > vue.js 실무 기능' 카테고리의 다른 글
11. vue로 Modal창, Modal Drag 구현 | v-for, v-if (0) | 2023.01.15 |
---|---|
10. vue.js 클래스에 숫자 넣고 싶을때 :clsss (0) | 2023.01.08 |
8. vue.js | window.open() 으로 Popup 만들기 (0) | 2022.11.22 |
7. jodit-vue 에디터 사용방법 (0) | 2022.11.15 |
6. vue.js | @clikc=""시 뒤로가기, 앞으로가기, main 이동 (0) | 2022.10.31 |