2017-10-03 2 views
1

이렇게 단어를 쓰는 방법을 모르겠지만 누군가가 세 개의 단추 중 하나를 클릭하면 단추를 누른 후 새 텍스트로 이동하게 될 때 시퀀스를 만들려고합니다. . 것은 그것을 시작하는 방법을 모른다. 다른 템플릿을 만들어야합니까, 아니면 내가 사용하고있는 템플릿을 사용할 수 있습니까? HTML :텍스트를 새 텍스트로 이동합니다.

<div id="app"> 

    <barista-template></barista-template> 
</div> 


    <!--template for customer--> 
<script type="text/x-template" id="b-template"> 
    <div> 
     <div>{{showText}}</div> 
     <button v-on:click="choose('drip')">Drip</button> 
     <button v-on:click="choose('frenchpress')">French Press</button> 
     <button v-on:click="choose('aeropress')">Aeropress</button> 
    </div> 
</script> 

<script type="text/x-template" id="c-template"> 
    <div> 
     <div>{{showText2}}</div> 
    </div> 
</script> 


<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.4/vue.min.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.1/TweenMax.min.js"></script> 
<script src="JS/app.js"></script> 
</body> 
</html> 

JS

Vue.component("customer-template",{ 
    template:"#c-template", 
    data:function(){ 
     return{ 
      order_type:"", 
     } 
    }, 
    computed:{ 
     showText2(){ 
      if(this.order_type === '') return ''; 
      return 'waiting for' + this.order_type 
     } 

    } 
}); 
Vue.component("barista-template",{ 
    template: "#b-template", 
    data: function() { 
     return{ 
      order_type:"", 
      order_value: "", 
     } 
    }, 
    computed: { 
     showText() { 
      if(this.order_type === '') return ''; 
      return 'One ' + this.order_type + ' that would be ' + this.order_value 
     } 
    }, 
    methods: { 
     choose: function (order_type) { 
      this.order_type = order_type; 

      if (this.order_type == "drip") { 
       this.order_value = "$10"; 
      } 
      if (this.order_type == "frenchpress") { 
       this.order_value = "$20"; 
      } 
      if (this.order_type == "aeropress") { 
       this.order_value = "$30"; 
      } 
     } 
    }, 
}); 
new Vue ({ 
    el:"#app", 
    data:function() { 
     return{ 
      showing:true 
     } 
    } 
}); 
+0

을 추가하고 '새로운 텍스트'로 이동 ,, 코드가 잘 작동 ,, 텍스트를 슬라이드 일부 트윈 또는 효과를 참조하지만합니까? 당신이 필요로하는 것의 느낌을 얻으려면 비슷한 URL이나 예제 URL을 공유하십시오. –

+0

미안합니다. 누군가가 세 개의 버튼 중 하나를 누르면 [showText2]는 'waiting for'+ this.order_type –

+0

그것이 내게 필요한 것이면 내 대답을 참조하십시오. –

답변

0

이 당신이 필요로하는 무엇인가? 하나의 템플릿은 당신이 무엇을 의미합니까 새 속성

Vue.component("barista-template",{ 
 
    template: "#b-template", 
 
    data: function() { 
 
     return{ 
 
      order_type:"", 
 
      order_value: "", 
 
     } 
 
    }, 
 
    computed: { 
 
     showText() { 
 
      if(this.order_type === '') return ''; 
 
      return 'One ' + this.order_type + ' that would be ' + this.order_value 
 
     }, 
 
     showText2(){ 
 
      if(this.order_type === '') return ''; 
 
      return 'waiting for ' + this.order_type 
 
     } 
 
    }, 
 
    methods: { 
 
     choose: function (order_type) { 
 
      this.order_type = order_type; 
 

 
      if (this.order_type == "drip") { 
 
       this.order_value = "$10"; 
 
      } 
 
      if (this.order_type == "frenchpress") { 
 
       this.order_value = "$20"; 
 
      } 
 
      if (this.order_type == "aeropress") { 
 
       this.order_value = "$30"; 
 
      } 
 
     } 
 
    }, 
 
}); 
 
new Vue ({ 
 
    el:"#app", 
 
    data:function() { 
 
     return{ 
 
      showing:true 
 
     } 
 
    } 
 
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.1/TweenMax.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.4/vue.min.js"></script> 
 

 

 
<div id="app"> 
 
    <barista-template></barista-template> 
 
</div> 
 

 

 

 

 
    <!--template for customer--> 
 
<script type="text/x-template" id="b-template"> 
 
    <div> 
 
     <div>{{showText}}</div> 
 
     <button v-on:click="choose('drip')">Drip</button> 
 
     <button v-on:click="choose('frenchpress')">French Press</button> 
 
     <button v-on:click="choose('aeropress')">Aeropress</button> 
 
     <div>{{showText2}}</div> 
 
    </div> 
 
</script> 
 

 
<script type="text/x-template" id="c-template"> 
 
    <div> 
 
     <div>{{showText2}}</div> 
 
    </div> 
 
</script>

+0

네, 그게 내가 찾고있는 것이지만, 세 번 버튼 중 하나를 누른 다음 드립을 기다리는 고객이 나타납니다. 예 : 고객 프레스 드립 [한 드립은 $ 10이됩니다] 그러면 새 텍스트가 바뀝니다 그것은 [물방울을 기다리고 있습니다]라고 말했습니다. –

+0

그래서 시간을 설정하는 방법이 필요하다고 생각 하시나요? –

+0

네, 텍스트를 대체 할 div에 ID를 넣고'setTimeout'을 사용하여 –

관련 문제