首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使文本转到新文本

使文本转到新文本
EN

Stack Overflow用户
提问于 2017-10-04 04:45:54
回答 1查看 55关注 0票数 1

所以我真的不知道怎么说,但我正在尝试创建一个序列,当有人点击三个按钮中的一个时,他们按下按钮后就会转到新文本。问题是我不知道该怎么开始。我是否需要创建另一个模板,或者我是否可以使用我正在使用的模板?HTML:

代码语言:javascript
复制
<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

代码语言:javascript
复制
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
        }
    }
});
EN

回答 1

Stack Overflow用户

发布于 2017-10-04 05:17:46

这是你需要的吗?一个模板和我添加了新属性

代码语言:javascript
复制
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
        }
    }
});
代码语言:javascript
复制
<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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46553131

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档