账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    为什么不能创建vue实例呢?
    20
    0

    <template>
    <div class="hello">

    <h1>{{ msg }}</h1>
    <h2>Essential Links</h2>
    <ul>
      <li>
        <a
          href="https://vuejs.org"
          target="_blank"
        >
          Core Docs
        </a>
      </li>
      <li>
        <a
          href="https://forum.vuejs.org"
          target="_blank"
        >
          Forum
        </a>
      </li>
      <li>
        <a
          href="https://chat.vuejs.org"
          target="_blank"
        >
          Community Chat
        </a>
      </li>
      <li>
        <a
          href="https://twitter.com/vuejs"
          target="_blank"
        >
          Twitter
        </a>
      </li>
      <br>
      <li>
        <a
          href="http://vuejs-templates.github.io/webpack/"
          target="_blank"
        >
          Docs for This Template
        </a>
      </li>
    </ul>
    <h2>Ecosystem</h2>
    <ul>
      <li>
        <a
          href="http://router.vuejs.org/"
          target="_blank"
        >
          vue-router
        </a>
      </li>
      <li>
        <a
          href="http://vuex.vuejs.org/"
          target="_blank"
        >
          vuex
        </a>
      </li>
      <li>
        <a
          href="http://vue-loader.vuejs.org/"
          target="_blank"
        >
          vue-loader
        </a>
      </li>
      <li>
        <a
          href="https://github.com/vuejs/awesome-vue"
          target="_blank"
        >
          awesome-vue
        </a>
      </li>
    </ul>
    <div id="showTest">
      <h1>{{msg2}}</h1>
      <h1>{{details()}}</h1>
    </div>

    </div>
    </template>

    <script>

    import Vue from 'vue'

    export default {
    name: 'HelloWorld',
    data () {

    return {
      msg: 'Welcome to Your Vue.js App'
    }

    }
    }

    var vm = new Vue({
    el: '#showTest',
    data () {

    return {
      msg2: 'this is only a test',
      state: 'is it success ?'
    }

    },
    methods: {

    details: function () {
      return this.state + ' you are right !!!! '
    }

    }
    })

    // Vue.use({
    // vm
    // })
    </script>

    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style scoped>
    h1,
    h2 {
    font-weight: normal;
    }
    ul {
    list-style-type: none;
    padding: 0;
    }
    li {
    display: inline-block;
    margin: 0 10px;
    }
    a {
    color: #42b983;
    }
    </style>

    显示错误说 'vm' is assigned a value but never used 所以我想知道如何引入自己创建的Vue对象

    0
    打赏
    收藏
    点击回答
        全部回答
    • 共 0 条
    • 傾旎 普通会员 1楼

      在Vue中,创建实例可以是直接使用new关键字,也可以是使用箭头函数。下面是两种方法的示例:

      1. 使用new关键字:

      javascript new Vue({ el: '#app', data: { message: 'Hello Vue!' } });

      1. 使用箭头函数:

      javascript const app = new Vue({ el: '#app', data: { message: 'Hello Vue!' } });

      在这两种方法中,Vue实例都会被创建。如果你想创建一个仅用于该实例的局部作用域变量,你可以使用闭包:

      ```javascript const app = new Vue({ data: { message: 'Hello Vue!' } });

      app.$data.myVariable = 'Hello Vue!';

      console.log(app.$data.myVariable); // 输出:Hello Vue! ```

      在这个例子中,myVariable是一个仅在app实例内部使用的局部变量。当app实例销毁时,myVariable也会被销毁。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部