Registro de aprendizaje de Vue

 

 

 

 

 

 

 

 

 

 

 

 

 Propiedades calculadas y oyentes

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <ul>
      <li>西游记; 价格:{
   
   {xyjPrice}},数量:<input type="number" v-model="xyjNum"></li>
      <li>西游记; 价格:{
   
   {shzPrice}},数量:<input type="number" v-model="shzNum"></li>
      <li>总价:{
   
   {totalPrice}}</li>
    </ul>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    new Vue({
      el:"#app",
      data:{
        xyjPrice:99.98,
        shzPrice:98.00,
        xyjNum: 1,
        shzNum:1
      },
      computed:{
        totalPrice(){
          return this.xyjPrice*this.xyjNum + this.shzPrice*this.shzNum;
        }
      }
    })
  </script>
</body>
</html>

 

 

<body>
  <div id="app">
    <button v-on:click="count++">我被点击了{
   
   {count}}次</button>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    new Vue({
      el:"#app",
      data:{
        count:1
      }
    })
  </script>
</body>

 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <button v-on:click="count++">我被点击了{
   
   {count}}次</button>
    <counter></counter>
  <counter></counter>
  <counter></counter>
  <counter></counter>
  <counter></counter>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    Vue.component("counter",{
      template:`<button v-on:click="count++">我被点击了{
   
   {count}}次</button>`,
      data(){
        return {
          count:1
        }
      }
    });


    new Vue({
      el:"#app",
      data:{
        count:1
      }
    })
  </script>
</body>
</html>

 

 

<button-counter></button-counter>

Supongo que te gusta

Origin blog.csdn.net/Hubery_sky/article/details/131648090
Recomendado
Clasificación