Vuejs:如何在异步导入加载中设置道具值?

Posted

技术标签:

【中文标题】Vuejs:如何在异步导入加载中设置道具值?【英文标题】:Vuejs: How to set props value in async import loading? 【发布时间】:2020-01-10 12:27:20 【问题描述】:

我正在尝试为我导入的异步组件设置加载组件。 这可行,但我会在安装它之前更改该组件的“颜色”道具。 我怎样才能做到这一点?

<script>
import loaderEllipsis from '@/components/common/loaderEllipsis.vue'
import SettingsNavigation from '@/components/views/Settings/SettingsNavigation.vue'

export default 
        name: 'view_settings',
        components: 

            loaderEllipsis,
            SettingsNavigation,
            SettingsOverview: function()
                return 
                loading: loaderEllipsis, //<-- I want to change the color props here before mount it.
                component: new Promise(function(resolve, reject) 
                    setTimeout(function() 
                        resolve(import(/* webpackChunkName: "settings-overview" */ '@/components/views/Settings/SettingsOverview.vue') );
                    , 15000);
                ),

                
            
        

</script>

无论如何,我尝试更改为道具颜色,但不起作用。 感谢您的帮助!

【问题讨论】:

【参考方案1】:

我创建了解决方案。

<script>
import loaderEllipsis from '@/components/common/loaderEllipsis.vue'
import SettingsNavigation from '@/components/views/Settings/SettingsNavigation.vue'

export default 
        name: 'view_settings',
        components: 

            loaderEllipsis,
            SettingsNavigation,
            SettingsOverview: function()
                return 
               loading: 
                    render: function(createElement) 
                        return createElement(loaderEllipsis, 
                            props: 
                                color: 'red'
                              
                        )
                    

                ,
                component: new Promise(function(resolve, reject) 
                    setTimeout(function() 
                        resolve(import(/* webpackChunkName: "settings-overview" */ '@/components/views/Settings/SettingsOverview.vue') );
                    , 15000);
                ),

                
            
        

</script>

【讨论】:

以上是关于Vuejs:如何在异步导入加载中设置道具值?的主要内容,如果未能解决你的问题,请参考以下文章

如何在 vue js 中设置输入表单控件默认聚焦,直到输入值?

如何在 laravel、vuejs 应用程序中设置 Paystack

如何在钩子中设置值

如何在 Vuejs 和 Node 中设置授权标头并保护路由

如何在Vuejs单元测试中设置或测试。$ parent?

如何在VueJS中将动态鼠标滚动值作为道具传递