集めたVue面接問題

9058 ワード

VUEライブラリ推奨URL:https://github.com/FEGuideTeam/FEGuide/blob/master/%E6%A1%86%E6%9E%B6/vue.md
 1   

##     mvvm?
	1. MVVM   Model-View-ViewModel    。mvvm        。Model        ,     Model                ;View    UI   ,            UI     ,ViewModel       View   Model    。

	2.   MVVM    ,View   Model           ,     ViewModel     ,Model   ViewModel          ,    View           Model  ,  Model              View  。

	3. ViewModel           View    Model       ,  View   Model              ,      ,             ,        DOM,               ,             MVVM      。

 2    

## mvvm   mvc   ?
mvc   mvvm        。        。     mvc   Controller     mvvm    viewModel。mvvm       mvc      DOM            ,      ,      。   Model       ,           View 。
	

 3   

## vue       ?
1.    。  (View)      Model      ,   ViewModel         "View" ,  View       Model     ,  Model       View      。
2.     。               ViewModel   ,    view         。
3.     。                   (ViewModel),             ,   Expression Blend              xml   。
4.    。            ,          ViewModel   。


 5   

##         vue        ?
 :     8       / ,   / ,   / ,   / 。
1.    / :   beforeCreate   ,vue         el    。
2.    / :  beforeMount   ,vue    $el   data      ,            dom   ,data.message     。  mounted   ,vue       ,data.message     。
3.    / :  data    ,    beforeUpdate   updated   。
4.    / :    destroy    ,  data             ,     vue                dom    ,   dom       

 6    

##        ?

1.          

//             


    //     
    import Main form "./main"

    exprot default{
        name:"parent",
        data(){
            return {
                data:"          "
            }
        },
        //     
        components:{
            Main
        }
    }



//     props      


    exprot default{
        name:"son",
        //       
        props:["data"]
    }



2.           

//     $emit      


    //     
    import Main form "./main"

    exprot default{
        methods:{
            events:function(){

            }
        }
    }



//



    exprot default{
        name:"son",
        //       
        props:["data"]
    }




 7    

## active-class         ?

	vue-router     router-link   。
 8   

##         ?
1. 	                      ,             ?        VueRouter        children   ,              。 index.html,        

2. main.js, , , home , home ,redirect path 。children , 。 import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) // import home from "./home.vue" import game from "./game.vue" // const routes = [ { path: "/", redirect: "/home" },// , home { path: "/home", component: home, children: [ { path: "/home/game", component: game } ] } ] // const router = new VueRouter({routes}) new Vue({ el: '#app', data: { }, methods: { }, router }) 3.home.vue, , , 。
 8    

##       ?
1.    (    ) 
2.    ( js   ) router.push('index')

 9.    

##    (      )(  )
	webpack      require.ensure()       。          import        ,   const          。
		1.	             :
			import  home   from '../../common/home.vue'
		2.              :
			const  home = r => require.ensure( [], () => r (require('../../common/home.vue')))

 10   

## vuex    ?    ?         ?
	vue        。  main.js    store,  。        store,….. export 。   :     ,       。    、    、     
	//    store.js
import vue from 'vue'
import vuex form 'vuex'
vue.use(vuex)
export default new vuex.store({
	//...code
})

//main.js
import store from './store'
...

 11   

## vue-router         ?
	  
		 :      
			1. outer.beforeEach(to, from, next),
			2. router.beforeResolve(to, from, next),
			3. router.afterEach(to, from ,next)
		 :     
			1. beforeRouteEnter,
		 	2. beforeRouteUpdate,
			3. beforeRouteLeave
		 :        
				beforeEnter

 12    

##      (v-check, v-focus)       ?         ?           
1.       :  vue     directive          ,        ,       。
2.        :directives
3.     : bind(      )、inserted(        )、update(       )
4.      : el、binding

	

 13    

##      4   vue           
	v-if(      )、v-for(       )、v-bind(    )、v-model(      )

 14    

## vue            (  )
	1. vue.js             -        ,   Object.defineProperty()         setter,getter,              ,         。
	2.      :    :   observe            ,          ,    setter   getter     ,           ,     setter,            
	3.     :compile       ,            ,           ,                 ,          ,       ,    ,    
	4.     :Watcher      Observer   Compile        ,       :
		             (dep)      
		        update()  
		      dep.notice()   ,       update()   ,    Compile       ,     。

	5.     :MVVM          ,   Observer、Compile   Watcher   ,   Observer        model     ,   Compile          ,     Watcher    Observer   Compile        ,       ->     ;      (input) ->    model          。

vuex相関
 15    

## vuex       
  5  ,    state、getter、mutation、action、module

 16    

## vuex   store      
1. vuex       ,         。   state         ,      vue       data
2. state             ,vue     store     ,   store         ,               
3.    mapState      state   getters          computed     

 17    

## vuex   getter      
1. getter     state       ,    store      
2.               ,   getters           
3.                ,      getters

 18    

## vuex   mutation      
1. action     muation,     :action      mutation,         
2. action           

 19    

## vue   ajax             methods     vuex   action  
	1.                  ,           ,       vuex   state  

	2.          ,       action  ,    ,     promise   
 20   

##    vuex        
1.        ,      ,     3    
2.      ,          ,              
3.     ,       ,          ,   Vue   Component         ,     ,         

 21    

## vuex   
	1. vuex       vue         ,   Redux,MobX            ,vuex       vue  ,               vue   computed              ,

	2. vuex         flux,                vue         ,    、        vue     Property set get        。        vuex     ,vuex    store        template       vue   ;


 22   

##    Vuex      Vue.use(Vuex),   Vue          store      ,store         ?  

	Vue.use(Vuex)        install   ,     Vue       init        ,     store        Vue       $store  。    Vue Component           this.$store      store。
 23    

## state              ,     ?  
	  store        makeLocalContext   ,   module       local context,       path     。      dispatch('submitOrder', payload)   action  ,        module   local state,              module   state,    rootState    path         。

 24    

##     dispatch    action(commit   )   ,    (type, payload),action            store       ?  
	store     ,      action   mutation    getters      。     dispatch('submitOrder', payload)   ,actions   type   submitOrder               ,           store   ,        { dispatch, commit, state, rootState }    。


 26   

## Vuex      state        ,     mutation      ?  
	Vuex     state           commit('xx', payload)   ,        this._withCommit(fn)   _committing       true,       state,         _committing   。             state,       _committing    ,     watch    state,state change      _committing    true,          。

 27    

##     "    "        ?  
	devtoolPlugin        。   dev        state change        ,'    '            state             state   ,   store.replaceState(targetState)       this._vm.state = state   。


axios
 28   

## axios    ?    ?              

1. axios           。 npm i axios -S

2.           ,        config/index.js