vue - 왜 하위 구성 요소의 데이터 옵션이 함수여야 합니까?

7694 단어
 1 
 2 "en">
 3 
 4     "UTF-8">
 5     Title
 6     "</span><span style="color:#800000;">../../vue.js</span><span style="color:#800000;">"</span>>
 7 
 8 
 9 
24 
"app"> 25 26 27 28 29 30 31 32
33 34 37 38 39 <span style="color:#008080;">40</span> <span style="color:#008000;">//</span><span style="color:#008000;"> data , , </span><span style="color:#008080;">41</span> <span style="color:#008000;">//</span><span style="color:#008000;"> , </span><span style="color:#008080;">42</span> <span style="color:#008000;">//</span><span style="color:#008000;"> data </span><span style="color:#008080;">43</span> <span style="color:#008000;">//</span><span style="color:#008000;"> let data = { </span><span style="color:#008080;">44</span> <span style="color:#008000;">//</span><span style="color:#008000;"> counter:0 </span><span style="color:#008080;">45</span> <span style="color:#008000;">//</span><span style="color:#008000;"> }; </span><span style="color:#008080;">46</span> <span style="color:#008000;">//</span><span style="color:#008000;"> data(){ </span><span style="color:#008080;">47</span> <span style="color:#008000;">//</span><span style="color:#008000;"> return data; </span><span style="color:#008080;">48</span> <span style="color:#008000;">//</span><span style="color:#008000;"> } </span><span style="color:#008080;">49</span> <span style="color:#008080;">50</span> <span style="color:#008000;">//</span><span style="color:#008000;">2. </span> <span style="color:#008080;">51</span> Vue.component(<span style="color:#800000;">'</span><span style="color:#800000;">my-btn</span><span style="color:#800000;">'</span><span style="color:#000000;">,{ </span><span style="color:#008080;">52</span> template:<span style="color:#800000;">'</span><span style="color:#800000;">#my_btn</span><span style="color:#800000;">'</span><span style="color:#000000;">, </span><span style="color:#008080;">53</span> <span style="color:#000000;"> data(){ </span><span style="color:#008080;">54</span> <span style="color:#0000ff;">return</span><span style="color:#000000;">{ </span><span style="color:#008080;">55</span> counter:<span style="color:#800080;">0</span> <span style="color:#008000;">//</span><span style="color:#008000;"> , counter , data ,</span> <span style="color:#008080;">56</span> <span style="color:#000000;"> } </span><span style="color:#008080;">57</span> <span style="color:#000000;"> } </span><span style="color:#008080;">58</span> <span style="color:#000000;"> }) </span><span style="color:#008080;">59</span> <span style="color:#008080;">60</span> <span style="color:#008080;">61</span> <span style="color:#0000ff;">var</span> vm = <span style="color:#0000ff;">new</span><span style="color:#000000;"> Vue({ </span><span style="color:#008080;">62</span> el:<span style="color:#800000;">'</span><span style="color:#800000;">#app</span><span style="color:#800000;">'</span><span style="color:#000000;">, </span><span style="color:#008080;">63</span> <span style="color:#000000;"> data:{} </span><span style="color:#008080;">64</span> <span style="color:#000000;"> }) </span><span style="color:#008080;">65</span> 66

 
전재 대상:https://www.cnblogs.com/wuhefeng/p/10024684.html

좋은 웹페이지 즐겨찾기