【问题标题】:How to use Vue.JS & Vue-Resource in Sails.JS? [closed]如何在 Sails.JS 中使用 Vue.JS 和 Vue-Resource? [关闭]
【发布时间】:2019-01-31 05:59:07
【问题描述】:

我是 Sails.JS 的新手,想在我的视图中使用 Vue.JS(每个 .ejs 都有一个脚本),但我不知道正确的方法。 如果我在视图末尾创建一个脚本标记,则会引发错误,因为 Vue.JS 尚未加载。所以,我在 assets 中创建了一个文件夹来保存我所有的 .js 文件,现在我不知道如何导入 Vue-Resource 而不会出现此错误:Cannot read property 'get' of undefined.

我已经检查了这个:https://github.com/pagekit/vue-resource/issues/579,但仍然没有成功。

感谢您的帮助!

【问题讨论】:

    标签: javascript vue.js sails.js vue-resource


    【解决方案1】:

    在你的 vue main.js 中确保你有

    var VueResource = require('vue-resource');
    Vue.use(VueResource);
    

    在 vue 模板中,您可以像这样访问它:

    <script>
        export default {
            data(){
                return {}
            },
            created(){
                console.log(typeof this.$http);
            },
            mounted(){
                console.log(typeof this.$http);
            }
        }
    </script>
    

    在处理资源时,我建议使用 Vuex 并使用状态来保存数据。 https://vuex.vuejs.org/

    【讨论】:

      猜你喜欢
      • 2017-07-22
      • 1970-01-01
      • 2017-11-20
      • 2017-05-27
      • 2017-12-30
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 2023-04-06
      相关资源
      最近更新 更多